Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JS minification doesn't work when module has exports #2591

Closed
keanulee opened this issue Apr 10, 2018 · 1 comment
Closed

JS minification doesn't work when module has exports #2591

keanulee opened this issue Apr 10, 2018 · 1 comment
Assignees

Comments

@keanulee
Copy link
Contributor

Versions & Environment

  • Polymer CLI: 1.7.0-pre.4

Steps to Reproduce

The ES module build output of shop-app.js and shop-checkout.js in the shop#lit-element branch have exports, and this causes warnings that prevent the ES module output from being minified.

➜  shop-3 git:(lit-element) ✗ polymer build
info:    Clearing build/ directory...
info:    (esm-bundled) Building...
info:    (es6-bundled) Building...
warn: [cli.build.optimize-streams]    js-transform: Unable to optimize /Users/keanulee/Code/Polymer/shop-3/src/components/shop-checkout.js 
{ err: 'Property local of ExportSpecifier expected node to be of a type ["Identifier"] but instead got "StringLiteral"' }
warn: [cli.build.optimize-streams]    js-transform: Unable to optimize /Users/keanulee/Code/Polymer/shop-3/src/components/shop-app.js 
{ err: 'Property local of ExportSpecifier expected node to be of a type ["Identifier"] but instead got "StringLiteral"' }
Could not resolve module specifier "require" in file "/Users/keanulee/Code/Polymer/shop-3/src/components/shop-app.js".
info:    (es5-bundled) Building...
Could not resolve module specifier "require" in file "/Users/keanulee/Code/Polymer/shop-3/src/components/shop-app.js".
info:    (esm-bundled) Build complete!
info:    (es5-bundled) Build complete!
info:    (es6-bundled) Build complete!

Expected Results

shop-app.js and shop-checkout.js bundles in build/esm-bundled/src/components/ are minified.

Actual Results

shop-app.js and shop-checkout.js bundles in build/esm-bundled/src/components/ are not minified.

@aomarks aomarks self-assigned this Apr 17, 2018
@aomarks
Copy link
Member

aomarks commented Apr 19, 2018

I tracked this down to a bug in Babel's minify-constant-folding plugin. I believe it is substituting value expressions directly into ExportSpecifiers (e.g. const foo = "foo"; export { foo }; becomes export { "foo" }; which is invalid.

babel/minify#820 was already filed, so I updated it with the additional information I found.

For our purposes, I think I'm just going to disable the minify-constant-folding plugin until this bug is fixed.

aomarks referenced this issue Apr 19, 2018
Disable Babel `minify-constant-folding` plugin when minifying. This
plugin has a bug that breaks when a constant is exported from a module
(babel/minify#820).

Fixes https://github.com/Polymer/polymer-cli/issues/998
aomarks referenced this issue Apr 20, 2018
Disable Babel `minify-constant-folding` plugin when minifying. This
plugin has a bug that breaks when a constant is exported from a module
(babel/minify#820).

Fixes https://github.com/Polymer/polymer-cli/issues/998
@aomarks aomarks transferred this issue from Polymer/polymer-cli Jan 3, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants