LasaleFamine / polymer-3-lit

Polymer 3 with lit-html implementation for rendering.
MIT License
7 stars 2 forks source link

Producing minimized bundle #1

Open tpluscode opened 7 years ago

tpluscode commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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!