jihchi/app-template-rescript-react

Specify in-source: false?

tom-sherman opened this issue · 3 comments

in-source: false allows Rescript files to be built to an external directory, instead of the build artefacts existing next to the source files.

Is this possible? I tried to specify it and tweak the mount options but I couldn't get it to work.

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
    public: { url: '/', static: true },
    'lib/es6/src': { url: '/dist' },
    src: { url: '/dist' },
  },
  plugins: [
    '@snowpack/plugin-react-refresh',
    '@snowpack/plugin-dotenv',
    [
      '@snowpack/plugin-run-script',
      {
        cmd: 'bsb -make-world',
        watch: '$1 -w',
      },
    ],
  ],
  packageOptions: {
    /* ... */
  },
  devOptions: {
    /* ... */
  },
  buildOptions: {
    /* ... */
  },
  alias: {
    /* ... */
  },
};

Yes, It seems like we couldn't assign two directories to serve /dist endpoint.


Also, I tried to add an new endpoint (/res) to serve lib/es6/src folder, unfortunately it does not works:

  1. Add an new endpoint /res which content is coming from lib/es6/src:
// snowpack.config.js
  mount: {
    public: { url: "/", static: true },
    "lib/es6/src": { url: "/res" },
    src: { url: "/dist" },
  },
  1. Change the endpoint of entry file in public/index.html:
// public/index.html
- <script type="module" src="/dist/index.bs.js"></script>
+ <script type="module" src="/res/index.bs.js"></script>
  1. When you open http://localhost:8080, http://localhost:8080/res/index.bs.js is loaded correctly but it couldn't load /res/index.css.proxy.js:
    2021-02-04 15-54-01(1)
  2. Because the dependency we are depending on still remains in src/ while the generated js has been moved to lib/es6/src:
// src/App.res
%%raw(`import './App.css';`)

I don't have a solution or workaround for this at the moment, this might be worthwhile to raise this issue in snowpack.