javascript - 通过 uglify-js 压缩的 Js 给出错误 Unexpected token : name ($)

标签 javascript jquery node.js bootstrap-4 uglifyjs

我正在通过 uglify-js 压缩我的 js 文件 我想压缩 Bootstrap 4 js 文件,但它给我这样的错误。 我可以只用 uglify-js 压缩所有 js 文件吗 或者 我该怎么做。

    Parse error at src\bootstrap\alert.js:1,7
    import $ from 'jquery'
           ^
    ERROR: Unexpected token: name ($)

我的 package.json

"devDependencies": {
    "node-sass": "^4.6.1",
    "nodemon": "^1.12.1"
  },
  "dependencies": {
    "autoprefixer": "^7.1.6",
    "jquery": "^3.2.1",
    "postcss-cli": "^4.1.1",
    "uglify-js": "^3.1.9"
  }

最佳答案

尝试使用 ES6 版本的 uglify-js。在您的 package.json

中替换为这个

"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"

或通过命令行:

npm install --save uglify-js@github:mishoo/UglifyJS2#harmony

关于javascript - 通过 uglify-js 压缩的 Js 给出错误 Unexpected token : name ($),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47286311/

相关文章:

javascript - 如何通过javascript在html中附加值

jquery - 删除点击事件的delay()

javascript - Nodejs,如何获取嵌套json对象中的值,中间键未知

javascript - Puppeteer 有什么方法可以从 Chrome 网络选项卡获取准确的数据吗?

javascript - Express:为 app.use 抽象出中间件

javascript - 有 <br> 时,使用 jQuery 的文本幻灯片无法正常运行

javascript - 在谷歌可视化数字格式中,当有负数时,我怎么能在美元符号前加上减号

javascript - 如何使用 Ember.run.later 实现秒表倒计时

jquery - 过渡不适用于高度 :0px

javascript - 使用 jQuery 和 Bootstrap 自动折叠嵌套列表