Giter Site home page Giter Site logo

Uglify error on build about deprecated HOT 22 CLOSED

ream avatar ream commented on April 27, 2024
Uglify error on build

from deprecated.

Comments (22)

egoist avatar egoist commented on April 27, 2024 2

Before babel-loader officially merges that PR, we use a fork of it for now. So this should be fixed in v1.0.0-beta.5 ream/ream@c2c5861

from deprecated.

cannap avatar cannap commented on April 27, 2024

i think the problem is here

export default { router } in index.js
try
export default { router:router } this is because uglifyjs i had this all the time in other projects

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

@cannap, I'm sure you're right that we could hack around this issue but there are a few important points to consider:

  1. It's not sensible to force every app to change its syntax just to get minification.

  2. I've been using Uglify for years (including on my current project that now has this issue with Ream) without this problem appearing, which means there's something we can change in how Ream is set up.

  3. The project I linked is the official custom server example (with some modifications so it actually runs). It's not good when the basic examples throw errors.

  4. Why is Uglify even seeing this syntax? Shouldn't Babel have transpiled that away?

from deprecated.

cannap avatar cannap commented on April 27, 2024
  1. yea sure

  2. me2

  3. dont know

  4. sure i had the same with the official vuejs webpack template... on DEV everything worked fine as i go in production this was the same problem as you have

from deprecated.

egoist avatar egoist commented on April 27, 2024

This is a bug I guess babel/babel-loader#433

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

That was fast. Great work by you and the babel-loader team.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

Actually, this seems to have only fixed some of the errors. Uglify still gets errors and only some files are minified. :-(

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

I tried to get a trimmed-down build but it doesn't seem to follow a specific pattern of what fails (i.e. I can't isolate a specific bit of code that does it alone). It just seems to have an issue with ES2015 generally.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

Is there a way to prevent the built-in ream uglification? I have read through the webpack-chain docs and the ream docs and some of the ream source code. I tried using .init(), .tap(), and just .plugin() alone, as well as .delete() but I couldn't make ream's build process not attempt minification through ream.config.js.

I want to have a go at adding minification myself to see if I can get it working.

from deprecated.

egoist avatar egoist commented on April 27, 2024

Check out https://github.com/ream/ream/blob/dev/lib/create-config.js#L222

config.plugins.delete('uglify')

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

Yes, that's the part of your source code I was reading.

I found the webpack-chain docs to be extensive but not very clear. I had tried config.plugin('uglify').delete() which didn't work.

I just tried what you suggested and that also didn't work. Uglify still ran. I also tried config.plugin.delete('uglify') (singular) and that didn't work.

Here is that part of my config:

extendWebpack(config, { type, dev }) {

    // use DefinePlugin to inject constants
    config
      .plugin('define')
      .use(webpack.DefinePlugin, [{
        '__VERSION__': `'${packageSpec.version}'`,
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
        'process.env.VUE_ENV': '"client"'
      }]);

    config.plugins.delete('uglify');

}

The define plugin works fine.

from deprecated.

egoist avatar egoist commented on April 27, 2024

Hmm, I guess you need to put shared config in ream.config.js and run npm run build since you're using the ream build command

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

The problem was that even though my server called it like this:

const reamConfig = require('./server/ream.config.js');
const reamApp = ream(Object.assign({ dev: process.env.NODE_ENV === 'development' }, reamConfig));

ream wasn't happy until I put ream.config.js in the root directory. I'm not sure why this is. Everything else seemed to work fine when it was in the other directory.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

Well, I just confirmed that ES2015 was causing UglifyJS to choke.

I fixed the problem by installing uglifyjs-webpack-plugin (to control which version of UglifyJS is used) and installing the harmony version of UglifyJS with this command:

$ yarn add git://github.com/mishoo/UglifyJS2#harmony --dev

All the errors disappeared.

I'm not sure why babel isn't doing its job of minifying. Or perhaps, babel is leaving the ES2015 that browsers can handle but UglifyJS isn't able to handle it?

I'm not sure if you want to make this change to ream's core.

More info here: https://github.com/webpack-contrib/uglifyjs-webpack-plugin

from deprecated.

egoist avatar egoist commented on April 27, 2024

Of course it's caused by ES2015 code since uglifyjs can't parse ES2015 code, the problem is why the ES2015 code isn't compiled down to ES5. Because we're using babel-preset-vue-app, everything should be compiled to be ie9-compatible.

By default the ream cli reads config file from $cwd, but you can use --config [path/to/ream.config.js] option.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

You're right, the server.js file never gets called so the build command needs to locate ream.config.js independently. I realised that after I posted the last comment.

I don't know why it's not being compiled down, but at least I've got my project back to a usable/deployable state with the workaround.

from deprecated.

egoist avatar egoist commented on April 27, 2024

Yeah, since your custom server is using the API while the build command is from the CLI.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

And at least now we're certain that these build bugs are caused purely by ES2015 incompatibility.

from deprecated.

egoist avatar egoist commented on April 27, 2024

@jazoom well how to reproduce that?

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

I couldn't. Even when I took the offending code from my complex app and put it in a stripped-down ream project the errors were not reproduced. That's what I meant before when I said it doesn't seem to follow a specific pattern.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

This is so weird. I'm no longer getting the UglifyJS errors (I switched back to default so I could find the root cause), but I can see in the built files that some ES2015 isn't getting transpiled. I can find spread operators, for example.

Again, when I put that same code into a minimal app, it transpiles fine.

from deprecated.

jazoom avatar jazoom commented on April 27, 2024

Ugh... I just deleted node_modules and rebuilt it and it seems to work okay. I'm pretty sure I did that already at least once. Anyway... I'm glad it's gone.

from deprecated.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.