zoukankan      html  css  js  c++  java
  • webpack4升级extract-text-webpack-plugin和UglifyJsPlugin问题

    webpack4升级extract-text-webpack-plugin和UglifyJsPlugin问题

    1.  使用了extract-text-webpack-plugin插件后,编译出错,代码如下:

    new ExtractTextPlugin('[name].css')

    报错信息如下:

    Tapable.plugin is deprecated. Use new API on `.hooks` instead 报错
    
    webpack is watching the files…
    
    (node:64840) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
     1 77% module and chunk tree optimization bound /Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/webpack/lib/Chunk.js:824
        throw new Error(
        ^
    
    Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
        at Chunk.get (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/webpack/lib/Chunk.js:824:9)
        at /Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/extract-text-webpack-plugin/index.js:260:39
        at Array.forEach (native)
        at ExtractTextPlugin.<anonymous> (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/extract-text-webpack-plugin/index.js:255:11)
        at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
        at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/tapable/lib/Hook.js:35:21)

    解决方案:用的应该是webpack4吧,换成mini-css-extract-plugin就好了,用法:https://www.npmjs.com/package/mini-css-extract-plugin

    2.使用new webpack.optimize.UglifyJsPlugin()时报错

    如下代码:

    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),

    报错信息如下:

    Error: webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead.
        at Object.get [as UglifyJsPlugin] (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/webpack/lib/webpack.js:174:10)
        at Object.<anonymous> (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/build/webpack.config.js:106:25)
        at Module._compile (/Users/tugenhua/工作文档/18年项目/xd-f2e-tyr/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)

    解决方案:

    1. webpack内置的JS压缩插件不能使用了,可以安装uglifyjs-webpack-plugin插件,使用同其他非内置插件;

    2. --mode production 表示生产环境,只要配置在package.json的script里面 js自动就压缩了

    注意:Uglify是压缩js,现在已经不需要了,只需要在script里面写成 "build": "webpack --mode production", 就自动压缩了。

  • 相关阅读:
    Base64编码原理分析
    对 js 高程 Preflighted Reqeusts 的理解
    js 跨域 之 修改服务器配置-XAMPP-Apache (nginx 拉到最后!)
    js 模拟 select 的 click 事件
    串讲-解释篇:作用域,作用域链,执行环境,变量对象,活动对象,闭包
    js 匿名函数-立即调用的函数表达式
    Java I/O流输入输出,序列化,NIO,NIO.2
    Java8Lambda表达式
    设计模式之适配器模式
    设计模式之装饰器设计模式
  • 原文地址:https://www.cnblogs.com/tugenhua0707/p/9526748.html
Copyright © 2011-2022 走看看