vue升级webpack版本到webpack4

用vue来实验下, 目的是把webpack3升级至^4.0

更新思路是

  1. 先更新
  2. 看是否废弃掉了
yarn global add @vue/cli-init 
vue init webpack hello_vue

cd hello_vue 
npm start

需要先验证工程是正确的, 可以运行后去看下webpack版本

发现是3.6

npm install webpack@latest -D
npm install webpack-dev-server@latest -D
npm i webpack-cli@latest -D
npm i html-webpack-plugin@latest -D
npm i eslint-loader@latest -D
npm i vue-loader@latest -D
npm i css-loader@latest -D
npm i postcss-loader@latest -D
npm start

根据npm start 报错来修改升级

然后发现

再去写入配置文件

配置和完成后就ok了

再去配置mode

npm run build

打包看下有没有错

去官方文档把对应的代码加到配置和pro中去

optimization: {
          splitChunks: {
               chunks: 'async',
               minSize: 30000,
               maxSize: 0,
               minChunks: 1,
               maxAsyncRequests: 5,
               maxInitialRequests: 3,
               automaticNameDelimiter: '~',
               automaticNameMaxLength: 30,
               name: true,
               cacheGroups: {
                    vendors: {
                         test: /[\\/]node_modules[\\/]/,
                         priority: -10
                    },
                    default: {
                         minChunks: 2,
                         priority: -20,
                         reuseExistingChunk: true
                    }
               }
          }
     }

注意有三个地方都要注释掉

然后发现报错:

Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead

npm install extract-text-webpack-plugin@next -D

next代表还没正式发布的版本, 是在latest之后的

然后就是报错

Error: Path variable [contenthash] not implemented in this context: static/css/[name].[contenthash].css

这样就正式更新至webpack4完成

转载于:https://my.oschina.net/sansenlian/blog/3084942

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值