一般webpack.config.js是默認放在根目錄的,不在根目錄的時候需要在package.json中制定位置,我的配置文件目錄是config/webpack.config.js,在package.json文件中的配置為:
"scripts": { "build": "webpack --mode production --config ./config/webpack.config.js", "dev": "webpack --mode development --config ./config/webpack.config.js" },
webpack.config.js文件中需要定義上下文地址為:
const path = require('path')
module.exports = {
//context:path.resolve(__dirname,'../'),這句不需要, __dirname指定的就是根目錄
entry: {
app: ['./src/index.js'],
about: ['./src/about.js']
},
output: {
path: path.resolve(__dirname,'../dist'),
filename: '[name].js',
}
};
