Extract drum operation time into a separate piece

When the Elm file is compiled, Elm runtime is extracted to the same file. Let me call this app.js file from now on. When even one byte is changed in app.js , the hash changes, as a result, the client downloads the file again, even if only one byte has changed. Is there a way to extract Elm runtime into a separate vendor (or commons ) snippet?

+7
webpack elm webpack-2
source share
1 answer

In Elm 0.18 and previous versions, the Elm core is included in each kit.

This can be inefficient, for example, if you download various Elm components to multiple pages. Each page will require its own package, but the Elm core will be included in each set.

Workaround (untested!)

  • Compile your Elm code into a package, output.js
  • Open output.js and from the beginning of the file to the last var declaration, which looks something like this:

     var _elm_lang$html$Html_Events$Options = F2( 

    Below this last variable declaration, starting with _elm_lang , you should see the code for the module you wrote. Where the division begins.

  • Copy and paste the entire fragment into a separate file and name it elm-core.js
  • TA-dah! Now you can load them into HTML files:

      <html> <script src="elm-core.js"></script> <script src="output.js"></script> </html> 

Caution! The entire output packet is wrapped in IIFE (the function expression is called immediately), so you have to wrap all the pieces in this to make sure that it works. If you do not, you will get errors such as F2 not defined "and" A2 - undefined ".

Elm 0.19 +

Future versions of Elm should have a better solution to this problem.

+4
source share

All Articles