webpack 3x 到webpack 4x 踩坑记录

从jspang的《Webpack3.X版 成神之路》webpack入门(http://jspang.com/posts/2017/...
现在升级到4x,菜鸟独自踩坑一把辛酸泪,webpack4主要教程参考https://blog.51cto.com/140471...
clipboard.pngcss

1.安装webpack

webpack 4x webpack和webpack-cli要分开安装,再也不一次安装
只在本地项目安装了webpack和webpack-clihtml

npm install webpack --save-dev
npm install webpack-cli --save-dev

查看webpack版本时用npx webpack -v
想一步到位,最好再全局安装一次webpack

npm install webpack -g
npm install webpack-cli -g

2.Webpack打包命令更改

webpack 3x打包命令web

webpack {entry file} {destination for bundled file}

{entery file}:入口文件的路径,本文中就是src/entery.js的路径;
{destination for bundled file}:填写打包后存放的路径。npm

webpack 4x打包命令更加严格
严格区分开发与生产环境,mode能够指定 production 或 development,不指定默认为 production。json

webpack {entry file} --output-filename {destination for bundled file} --output-path --mode development

简写:webpack {entry file} -o {destination for bundled file} --mode developmentsegmentfault

一样咱们能够在package.json里配置,简化命令jsp

"dev": "webpack --mode development",
"build": "webpack --mode production"

3.postcss-loader autoprefixer配置后不起做用

具体安装过程看jspang的博客http://jspang.com/posts/2017/... 第十三节 自动处理CSS3属性前缀ide

都配置以后发现不起做用
查了以后发现autoprefixer须要配置browsers参数兼容版本,但配置以后报错post

clipboard.png

autoprefixer引用更改,语法改成overrideBrowserslist

更改前:
module.exports = {
    plugins: [
        require('autoprefixer')({ browsers: ["last 5 versions"]})
    ]
}

更改后:
module.exports = {
    plugins: [
        require('autoprefixer')({ overrideBrowserslist: ["last 5 versions"]})
    ]
}

详细兼容见http://www.ydcss.com/archives/94,https://segmentfault.com/a/1190000008030425

相关文章
相关标签/搜索