vue-cli run dev正常,运行run build提示出错,webpack已resolve相关modules


ERROR in static/js/vendor.cce10fda4a9a074cd1d7.js from UglifyJs
Unexpected token: punc (() [./~/_dom7@2.0.0@dom7/src/methods.js:7,0][static/js/vendor.cce10fda4a9a074cd1d7.js:10294,10]

  Build failed with errors.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hgui@1.0.0 build: `node build/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the hgui@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-09-29T12_05_58_655Z-debug.log

根据回答,我试了一下将dom7这个modules也加入到webpack的babel-loader:

 {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test'),resolve('node_modules/_dom7@2.0.0@dom7/src')]
      },

接下来显示的却是:

ERROR in static/js/vendor.b4322554ee076d6e4c5e.js from UglifyJs
Unexpected token: name (w) [./~/_swiper@4.0.0-beta.4@swiper/dist/js/swiper.module.js:16,0][static/js/vendor.b4322554ee076d6e4c5e.js:11543,4]

  Build failed with errors.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hgui@1.0.0 build: `node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hgui@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-09-29T17_13_49_547Z-debug.log

感觉这样子下去要没完没了了。
然后我再:

      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test'),resolve('node_modules/_dom7@2.0.0@dom7/src'),resolve('node_modules/_swiper@4.0.0-beta.4@swiper')]
      },

最后


> node build/build.js

⠴ building for production...Killed

这是什么情况?如果我想引入这个插件我应该如何配置这个webpack?

阅读 6.5k
4 个回答

我是vue-cli架的手脚,我用swiper也是报一样的错误,用这个vue-awesome-swiper,在swiper进行vue封装,用起来一毛一样 压缩不出错,

import { swiper, swiperSlide } from 'vue-awesome-swiper'

clipboard.png

看起来像是在使用 UglifyJs 压缩的时候有了问题,打包的时候打进了内置的模块,压缩出现了问题。很可能是 ES6 的问题?可以手动升级一下 uglify 的版本重新试试。

有可能内存不足,你看看

新手上路,请多包涵

看来这个问题很严重啊,不写这个exclude规则,vue项目引入swiper,在部分低级的手机浏览器里白页,加上exclude规则,vue-lazyload、vconsole报错,不知道该怎么解决了,swiper官方不修复这些问题?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题