1: 默认entry和output
最新版本的webpack已经可以不需要webpack.config.js作为配置文件。如果你的项目缺失配置文件的话,webpack会做以下默认配置:
entry - src/index.jsoutput - dist/main.js
2: 默认配置文件 vs 制定配置文件
如果项目根目录有webpack.config.js文件,那webpack会默认使用它作为配置文件。我们也可以自己在命令行里通过 --config 指定配置文件,例如:
"scripts": { "build": "webpack --config prod.config.js"}
3: path
webpakc使用node.js内置的path库来处理路径:
const path = require('path')
你可能还会注意到这个变量:__dirname
__dirname 的值就是当前module的路径,它和对__filename执行path.dirname()是一样的。例如:在/Users/mjr 路径下执行node example.js,那么:
console.log(__dirname);// Prints: /Users/mjrconsole.log(path.dirname(__filename));// Prints: /Users/mjr