philipwalton / webpack-esnext-boilerplate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When esnext bundle gets minified, it doesn't work

jakub-g opened this issue · comments

As mentioned in #5, .mjs files are not minified when using NODE_ENV=production npm start

This can be fixed by either renaming .mjs files to .js in the build config and templates, or by updating terser config to minify .mjs files.

However in any case, after minification gets enabled, when running NODE_ENV=production npm start and launching localhost:8080, the app doesn't work -- nothing happens, nothing is logged to console, and almost all code is marked as non-executed in Chrome coverage tool:

image

It seems that minification of the esnext bundle does something weird that prevents the code from booting up.

The issue comes from terser config, with the existing config it mangles all props, including stuff exposed on window like window.webpackJsonp gets renamed to a different prop name in each file.

Diff to fix it:

       terserOptions: {
         mangle: {
-          properties: /(^_|_$)/,
+          properties: {
+            regex: /(^_|_$)/,
+          },
         },