91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

webpack3.0升級4.0的方法步驟

發布時間:2020-09-10 23:12:02 來源:腳本之家 閱讀:210 作者:_kangzai 欄目:web開發

1.webpack 3.11升級4.26

為了提升打包效率,在webpack3.11基礎之上做了升級,webpack4.0發布以來,零配置的webpack對項目本身提供的“打包”和“壓縮”功能已經做了優化,如果在項目開始使用4.0而不用vue-cli的默認配置,遇到的問題或許能少一些。

2. 安裝/升級依賴

這些依賴有的是在build過程中發現依賴有新的替換或者報錯,逐步替換的,如果想遇到多個坑,可以先把webpack、webpack-cli升級到對應版本

devDependencies:

"extract-text-webpack-plugin": "^4.0.0-beta.0"
"html-webpack-plugin": "^4.0.0-beta.14"
"mini-css-extract-plugin": "^0.9.0" (舊的optimize-css-assets-webpack不支持了)
"preload-webpack-plugin": "^3.0.0-beta.4"
"script-ext-html-webpack-plugin": "^2.1.3"
"vue-loader": "^15.3.0"
"webpack": "^4.26.1"
"webpack-cli": "^3.1.2"
"webpack-dev-server": "^3.2.1"
"script-ext-html-webpack-plugin": "^2.1.3"

3. 遇到的問題

升級webpack后,build報錯:ERROR in ./src/App.vue
Module Error (from ./node_modules/vue-loader/lib/index.js

解決:升級vue-loader至15.3.0,

webpack.base.conf.js添加

const {VueLoaderPlugin} = require('vue-loader')
module.exports中添加
 plugins:[new VueLoaderPlugin()]

修改配置文件 webpack.prod.conf.js:

webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.

解決:

webpack.prod.conf.js webpackConfig配置:
optimization: {
 noEmitOnErrors: true,
 concatenateModules: true,
 splitChunks: {
  chunks: 'all',
  name: 'common',
 },
 runtimeChunk: {
  name: 'runtime'
 }
 }
webpack.prod.conf.js webpackConfig配置: 
optimization:{
 namedModules: true
 },

Plugin could not be registered at ‘html-webpack-plugin-before-html-processing'. Hook was not found.

解決:

npm i preload-webpack-plugin@next -D

Tapable.plugin is deprecated. Use new API on .hooks instead

問題:extract-text-webpack-plugin兼容問題 ,功能:extract css into its own file

解決: 卸載extract-text-webpack-plugin,安裝mini-css-extract-plugin

 new MiniCssExtractPlugin({
  filename: utils.assetsPath('css/[name].[contenthash].css'),
  allChunks: false,
 }),

build出錯:ERROR in TypeError: Cannot read property ‘hash' of undefined

解決:

  去掉這段
  //打包計時
  const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
  const smp = new SpeedMeasurePlugin();

WARNING in configuration
The ‘mode' option has not been set, webpack will fallback to ‘production' for this value. Set ‘mode' option to ‘development' or ‘production' to enable defaults for each environment.
You can also set it to ‘none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/

解決:webpackConfig添加 mode: ‘production'

Tapable.plugin is deprecated. Use new API on .hooks instead

解決:

npm i --save-dev extract-text-webpack-plugin@next

會下載到 extract-text-webpack-plugin@4.0.0-beta

Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.o ptimization…

解決:

  • 去掉 webpack.optimize.CommonsChunkPlugin相關配置
  • webpackConfig中與plugins的同級添加
optimization: {
 splitChunks: {
   cacheGroups: {
    commons: {
     name: "commons",
     chunks: "initial",
     minChunks: 2
    }
   }
  }
 },

Unhandled rejection Error: “dependency” is not a valid chunk sort mode

new HtmlWebpackPlugin({
  filename: config.build.index,
  template: 'index.html',
  inject: true,
  minify: {
  removeComments: true,
  collapseWhitespace: true,
  removeAttributeQuotes: true
  },
  // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  chunksSortMode: 'dependency'
 }),

解決:chunksSortMode改為auto或者注釋

至此:npm run build 正常
接下來調npm run dev,直接運行成功

4. 總結

開啟cache的情況下,原來打包時間22s左右,現在build最快8s左右

升級思路:

  1. 卸載webpack舊版本、安裝新版本webpack, webpack-cli
  2. 遇到loader、plugin報錯,升級loader、plugin,有的在4.0不支持,需要換成新的
  3. 卸載 ExtractTextPlugin、刪除對應配置,改用 mini-css-extract-plugin
  4. 配置環境mode
  5. 其它wenpack3.0優化配置兼容處理

到此這篇關于webpack3.0升級4.0的方法步驟的文章就介紹到這了,更多相關webpack3.0升級4.0內容請搜索億速云以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持億速云!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

黑山县| 静海县| 罗平县| 西平县| 平陆县| 盐池县| 安化县| 桐乡市| 托克逊县| 洛隆县| 乐清市| 台北县| 许昌市| 靖州| 随州市| 临漳县| 遂宁市| 梨树县| 柳州市| 普兰县| 和田县| 绥棱县| 龙岩市| 津市市| 英山县| 潼南县| 洪江市| 祥云县| 沾益县| 陆川县| 余干县| 六安市| 泰州市| 麻阳| 罗山县| 安义县| 连江县| 延寿县| 冕宁县| 商河县| 贵南县|