Skip to content

Commit 0486adf

Browse files
authored
Merge pull request #186 from halfzebra/disablinb-dead-code-elimination
feat($config): Enable users to disable dead code elimination by setti…
2 parents 3813c89 + a7493be commit 0486adf

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

config/webpack.config.prod.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ const extractTextPluginOptions = shouldUseRelativeAssetPaths
3737
{ publicPath: Array(cssFilename.split('/').length).join('../') }
3838
: {};
3939

40+
// Enable users to turn off dead code elimination.
41+
const deadCodeElimination =
42+
process.env.DEAD_CODE_ELIMINATION !== 'true'
43+
? {
44+
dead_code: true,
45+
pure_funcs: [
46+
'_elm_lang$core$Native_Utils.update',
47+
'A2',
48+
'A3',
49+
'A4',
50+
'A5',
51+
'A6',
52+
'A7',
53+
'A8',
54+
'A9',
55+
'F2',
56+
'F3',
57+
'F4',
58+
'F5',
59+
'F6',
60+
'F7',
61+
'F8',
62+
'F9'
63+
]
64+
}
65+
: {};
66+
4067
module.exports = {
4168
// Don't attempt to continue if there are any errors.
4269
bail: true,
@@ -185,29 +212,12 @@ module.exports = {
185212

186213
// Minify the compiled JavaScript.
187214
new UglifyJsPlugin({
188-
compress: {
189-
warnings: false,
190-
dead_code: true,
191-
pure_funcs: [
192-
'_elm_lang$core$Native_Utils.update',
193-
'A2',
194-
'A3',
195-
'A4',
196-
'A5',
197-
'A6',
198-
'A7',
199-
'A8',
200-
'A9',
201-
'F2',
202-
'F3',
203-
'F4',
204-
'F5',
205-
'F6',
206-
'F7',
207-
'F8',
208-
'F9'
209-
]
210-
},
215+
compress: Object.assign(
216+
{
217+
warnings: false
218+
},
219+
deadCodeElimination
220+
),
211221
output: {
212222
comments: false
213223
}

template/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ You can find the most recent version of this guide [here](https://github.com/hal
2020
- [make](#make)
2121
- [reactor](#reactor)
2222
- [Turning on/off Elm Debugger](#turning-onoff-elm-debugger)
23+
- [Dead code elimination](#dead-code-elimination)
2324
- [Changing the Page `<title>`](#changing-the-page-title)
2425
- [Adding a Stylesheet](#adding-a-stylesheet)
2526
- [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
168169

169170
To turn on/off Elm Debugger explicitly, set `ELM_DEBUGGER` environment variable to `true` or `false` respectively.
170171

172+
## Dead code elimination
173+
174+
Create Elm App comes with an opinionated setup for dead code elimination which is disabled by default, because it may break your code.
175+
176+
You can enable it by setting `DEAD_CODE_ELIMINATION` environment variable to `true`
177+
171178
## Changing the base path of the assets in the HTML
172179

173180
By default, assets will be linked from the HTML to the root url. For example `/css/style.css`.

0 commit comments

Comments
 (0)