Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Webpack uglify #10

Closed
tushar-1health opened this issue Jun 14, 2017 · 12 comments
Closed

Webpack uglify #10

tushar-1health opened this issue Jun 14, 2017 · 12 comments

Comments

@tushar-1health
Copy link

Hello,

Webpack without uglify works fine. However, with --uglify flag it fails with following error.

ERROR in bundle.js from UglifyJs
Unexpected token: name (localStorageData) [bundle.js:73561,8]
@EddyVerbruggen
Copy link

Yep, same here. Can be fixed by replacing all let's by var's in localstorage.js. I just forked this repo and changed that. Can do a PR if yall think this is the best solution.

@NathanaelA
Copy link
Owner

The issue is that Uglify didn't support ES6. mishoo/UglifyJS#448
The newer version Uglify-es supports ES6 but NativeScript Webpack version currently doesn't supported the Uglify-es yet. At the point NativeScript and WebPack catch up; ES6 code will then work fine.

I'm not really keen on downgrading ES6 code to older ES5 code; seems like a big step backwards.

@EddyVerbruggen
Copy link

I understand, no worries.

@tushar-1health be welcome to use my fork of this nice plugin and switch back to this one whenever ES6 is supported.

@jibon57
Copy link

jibon57 commented Aug 14, 2017

Yes, @EddyVerbruggen . I have solved this here: #12

@Guatom
Copy link

Guatom commented Sep 11, 2017

Hey guys! I've been having this problem with several other plugins and I agree with @NathanaelA that downgrading the source code just for the sake of Uglify is not a good option.

I ended up adding babel-loader only for these ES6 plugins, something like this in webpack.config.js:

// Transpile ES6+ files
{
  test: /\.js$/,
    loader: "babel-loader",
      include: [
        resolve(__dirname, 'node_modules/nativescript-sms-inbox'),
        resolve('nativescript-contacts-lite'),
      ],
        query: {
    presets: [
      [
        "es2015",
        {
          "targets": {
            "uglify": false
          }
        }
      ]
    ]
  }
}

Hope this helps.

@NathanaelA
Copy link
Owner

@Guatom - Excellent solution, thanks for commenting.

@bfv
Copy link

bfv commented Oct 20, 2017

If you upgrade UglifyJS to version 3 ES6 is supported, see: NativeScript/nativescript-angular#1011 (the sis0k0 post). Worked for me to webpack/ugilfy a project with this plugin.

@rigoparis
Copy link

rigoparis commented May 24, 2018

This happens while using {N}-Vue's template

https://github.com/nativescript-vue/vue-cli-template

@NathanaelA
Copy link
Owner

@rigoparis - Can you tell me which version of Webpack you are using; the uglify issue should have been fixed a while back by the NativeScript team when they started using v1.x of the uglify plugin.

@samtgarson
Copy link

@NathanaelA I believe the {N}-Vue template has not yet been updated to a later version of Webpack.

@rigoparis I've solved this temporarily using the quick solution in this comment—basically using require('uglifyjs-webpack-plugin) instead of webpack.optimize.UglifyJsPlugin

@NathanaelA
Copy link
Owner

@samtgarson - Sam thanks for the status update; I would have expected that Igor was using the latest version of the NS webpack in the Vue stuff...

@NathanaelA
Copy link
Owner

This should now be fixed; NS-Vue should be using the latest Webpack. 😀

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

No branches or pull requests

8 participants