Skip to content

Commit

Permalink
Merge pull request #315 from andys8/feature/dead-code-elimination-0.19
Browse files Browse the repository at this point in the history
Uglifyjs configuration for elm 0.19
  • Loading branch information
halfzebra authored Nov 4, 2018
2 parents af1b04f + 6e0380b commit ffd259e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 50 deletions.
76 changes: 34 additions & 42 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,7 @@ const publicUrl = publicPath.slice(0, -1);
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);

const useDebugger = process.env.ELM_DEBUGGER === 'true' ? true : false;

// Enable users to turn on 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'
]
}
: {};
const useDebugger = process.env.ELM_DEBUGGER === 'true';

// This is the production configuration.
// It compiles slowly and is focused on producing a fast and minimal bundle.
Expand Down Expand Up @@ -86,18 +59,38 @@ module.exports = {
// ES5 is required in the minified code if you want compatibility with IE11,
// otherwise you can bump it up to ES8
ecma: 5,
compress: Object.assign(
{},
{
warnings: false,
// Disabled because of an issue with Uglify breaking seemingly valid code:
// https://github.com/facebook/create-react-app/issues/2376
// Pending further investigation:
// https://github.com/mishoo/UglifyJS2/issues/2011
comparisons: false
},
deadCodeElimination
),
// Compression settings mostly based on <https://guide.elm-lang.org/optimization/asset_size.html>
compress: {
passes: 2,
warnings: false,
// Disabled because of an issue with Uglify breaking seemingly valid code:
// https://github.com/facebook/create-react-app/issues/2376
// Pending further investigation:
// https://github.com/mishoo/UglifyJS2/issues/2011
comparisons: false,
pure_getters: true,
keep_fargs: false,
unsafe_comps: true,
unsafe: true,
pure_funcs: [
'A2',
'A3',
'A4',
'A5',
'A6',
'A7',
'A8',
'A9',
'F2',
'F3',
'F4',
'F5',
'F6',
'F7',
'F8',
'F9'
]
},
mangle: {
safari10: true
},
Expand Down Expand Up @@ -129,7 +122,6 @@ module.exports = {
modules: ['node_modules'],
extensions: ['.js', '.elm']
},

module: {
strictExportPresence: true,

Expand Down Expand Up @@ -212,7 +204,7 @@ module.exports = {
}
},
{
// Use the local installation of elm-make
// Use the local installation of elm make
loader: require.resolve('elm-webpack-loader'),
options: {
// If ELM_DEBUGGER was set to "true", enable it. Otherwise
Expand Down
4 changes: 1 addition & 3 deletions template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ To turn on/off Elm Debugger explicitly, set `ELM_DEBUGGER` environment variable

## 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`
Create Elm App comes with an setup for dead code elimination which relies on the elm compiler flag `--optimize` and `uglifyjs`.

## Changing the base path of the assets in the HTML

Expand Down
6 changes: 1 addition & 5 deletions tests/create-elm-app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ describe('Create Elm application with `create-elm-app` command', () => {
}).timeout(60 * 1000);

it(`'${testAppName}' should have elm.json file`, () => {
expect(
fs.existsSync(path.join(testAppDir, 'elm.json')),
'to be',
true
);
expect(fs.existsSync(path.join(testAppDir, 'elm.json')), 'to be', true);
});

it(`'${testAppName}' should have .gitignore file`, () => {
Expand Down

0 comments on commit ffd259e

Please sign in to comment.