先看package.json里的命令:
1 "scripts": { 2 "dev": "webpack-dev-server --inline --progress --config 3 build/webpack.dev.conf.js", 4 "build": "node build/build.js", 5 },
1.本地启动开发环境
最后使用的配置文件是
1 build/webpack.dev.conf.js
2.打包到生产的配置文件是
1 build/build.js
即,开发环境和生产环境的配置是分开的;
3.那么查看开发环境的配置直接到build/webpack.dev.conf.js文件中,文件中通过配置process.env来配置开发环境相关路径
1 plugins: [ 2 new webpack.DefinePlugin({ 3 'process.env':require('../config/dev.env') 4 }) 5 ]
同样在build/webpack.prod.conf.js文件中,也通过配置process.env来配置生产环境相关路径
1 plugins: [ 2 new webpack.DefinePlugin({ 3 'process.env':require('../config/prod.env') 4 }) 5 ]
在build/build.js中引入了build/webpack.prod.conf.js;
4.一般配置有build和config两个文件夹,
build文件夹结构如下:
build/build.js
build/webpack.base.conf.js
build/webpack.dev.conf.js(会引入合并build/webpack.base.conf.js文件配置)
build/webpack.prod.conf.js(会引入合并build/webpack.base.conf.js文件配置)
conf文件夹结构如下:
conf/index.js(基础配置,build中都会引入)
conf/dev.env.js(开发环境路径配置)
conf/prod.env.js (生产环境路径配置)