目錄css
用vue來實驗下, 目的是把webpack3升級至^4.0html
更新思路是vue
yarn global add @vue/cli-init vue init webpack hello_vue
cd hello_vue npm start
須要先驗證工程是正確的, 能夠運行後去看下webpack版本node
發現是3.6webpack
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 報錯來修改升級web
而後發現npm
再去寫入配置文件async
配置和完成後就ok了webpack-dev-server
再去配置modepost
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完成