From 44f017770f38e5df4543deda40b42c132122d56d Mon Sep 17 00:00:00 2001 From: Eduard Kyvenko Date: Tue, 10 Oct 2017 22:53:21 +0200 Subject: [PATCH 1/3] feat($config): Enable users to disable dead code elimination by setting `DEAD_CODE_ELIMINATION` to ` --- config/webpack.config.prod.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index 0897dbcf..20941efd 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -187,7 +187,8 @@ module.exports = { new UglifyJsPlugin({ compress: { warnings: false, - dead_code: true, + // Enable users to turn off dead code elimination. + dead_code: process.env.DEAD_CODE_ELIMINATION !== 'false', pure_funcs: [ '_elm_lang$core$Native_Utils.update', 'A2', From d5fd36fef4cbe5619162a6b4b3153a102d36b31d Mon Sep 17 00:00:00 2001 From: Eduard Kyvenko Date: Thu, 26 Oct 2017 17:50:30 +0200 Subject: [PATCH 2/3] feat: Dead code elimination is disabled by default Added an opinionated config for performing dead code elimination, which could be enabled by setting `DEAD_CODE_ELIMINATION` environment variable to `true` --- config/webpack.config.prod.js | 57 ++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index 20941efd..d3b592fe 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -37,6 +37,33 @@ const extractTextPluginOptions = shouldUseRelativeAssetPaths { publicPath: Array(cssFilename.split('/').length).join('../') } : {}; +// Enable users to turn off dead code elimination. +const deadCodeElimination = + process.env.DEAD_CODE_ELIMINATION !== 'true' + ? { + dead_code: true, + pure_funcs: [ + '_elm_lang$core$Native_Utils.update', + 'A2', + 'A3', + 'A4', + 'A5', + 'A6', + 'A7', + 'A8', + 'A9', + 'F2', + 'F3', + 'F4', + 'F5', + 'F6', + 'F7', + 'F8', + 'F9' + ] + } + : {}; + module.exports = { // Don't attempt to continue if there are any errors. bail: true, @@ -185,30 +212,12 @@ module.exports = { // Minify the compiled JavaScript. new UglifyJsPlugin({ - compress: { - warnings: false, - // Enable users to turn off dead code elimination. - dead_code: process.env.DEAD_CODE_ELIMINATION !== 'false', - pure_funcs: [ - '_elm_lang$core$Native_Utils.update', - 'A2', - 'A3', - 'A4', - 'A5', - 'A6', - 'A7', - 'A8', - 'A9', - 'F2', - 'F3', - 'F4', - 'F5', - 'F6', - 'F7', - 'F8', - 'F9' - ] - }, + compress: Object.assign( + { + warnings: false + }, + deadCodeElimination + ), output: { comments: false } From a7493be646832b24a1d84cb5e451e489cef723ae Mon Sep 17 00:00:00 2001 From: Eduard Kyvenko Date: Fri, 27 Oct 2017 10:43:32 +0200 Subject: [PATCH 3/3] docs: Added docs about dead code elimination --- template/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/template/README.md b/template/README.md index ea91c764..37b1b496 100644 --- a/template/README.md +++ b/template/README.md @@ -20,6 +20,7 @@ You can find the most recent version of this guide [here](https://github.com/hal - [make](#make) - [reactor](#reactor) - [Turning on/off Elm Debugger](#turning-onoff-elm-debugger) +- [Dead code elimination](#dead-code-elimination) - [Changing the Page ``](#changing-the-page-title) - [Adding a Stylesheet](#adding-a-stylesheet) - [Post-Processing CSS](#post-processing-css) @@ -168,6 +169,12 @@ By default, in production (`elm-app build`) the Debugger is turned off and in de To turn on/off Elm Debugger explicitly, set `ELM_DEBUGGER` environment variable to `true` or `false` respectively. +## Dead code elimination + +Create Elm App comes with an opinionated setup for dead code elimination which is disabled by default, because it may break your code. + +You can enable it by setting `DEAD_CODE_ELIMINATION` environment variable to `true` + ## Changing the base path of the assets in the HTML By default, assets will be linked from the HTML to the root url. For example `/css/style.css`.