Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Producing minimized bundle #1

Open
tpluscode opened this issue Aug 27, 2017 · 5 comments
Open

Producing minimized bundle #1

tpluscode opened this issue Aug 27, 2017 · 5 comments

Comments

@tpluscode
Copy link

tpluscode commented Aug 27, 2017

When I run webpack --optimize-minimize I get error:

ERROR in bundle.js from UglifyJs
Unexpected token: name (Polymer) [bundle.js:73,4]

That's this line:

/** @namespace */
let Polymer;

Any ideas?

@LasaleFamine
Copy link
Owner

Could be an UglifyJs problem to digest ESNext syntax?

I'm trying to figure this out, maybe we can consider to add https://github.com/babel/minify instead of the standard UglifyJs minifier called by the --optimize-minimize. Do you think could be a solution?

Or maybe another solution could be transpiling to ES5, but I need to test, and of course after that we will need the custom-elements-es5-adapter.js for the app.

@tpluscode
Copy link
Author

I did try with ES5 but somehow anything I tried also produced some error. In the end I think it wasn't even transpiling. I'm not sure how to do that properly. I've mostly written TS myself 😞

@LasaleFamine
Copy link
Owner

LasaleFamine commented Aug 28, 2017

Did you try to minify with the babel/minify?

I found that it works as expected with this webpack.conf.js:

const path = require('path');
const webpack = require('webpack');
const MinifyPlugin = require('babel-minify-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'src'),
    filename: 'bundle.js'
  },
  plugins: [
    new MinifyPlugin()
  ]
};

NOTE: I think we can't use the --optimize-minimize option because it works with UglifyJs and other default options that seem don't support ES6.
Maybe defining the babel-loader and UglifyJs within the webpack configuration we can achieve the same result of --optimize-minimize option.

@tpluscode
Copy link
Author

With MinifyPlugin it bundled without errors but in console I'm seeing

SyntaxError: Cannot declare a let variable twice: 'd'.

I tried with babel-loader and various combinations of presets but every time the output was ES6 and not ES5. Don't know why...

@LasaleFamine
Copy link
Owner

Yeah, I'm seeing the same problem. Thank you for your upgrades and info.
I will try some other solution, then maybe I will ask on the Polymer Slack.

Let's leave this issue open until we found a solution.
Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants