要创建两个不同的JavaScript文件并使用不同的Webpack配置,可以按照以下步骤进行操作:
file1.js
和file2.js
,并将它们放置在适当的目录中。webpack.config1.js
和webpack.config2.js
。webpack.config1.js
中配置第一个JavaScript文件的打包规则和其他相关配置。例如:const path = require('path');
module.exports = {
entry: './path/to/file1.js',
output: {
filename: 'bundle1.js',
path: path.resolve(__dirname, 'dist'),
},
// 其他配置项...
};
webpack.config2.js
中配置第二个JavaScript文件的打包规则和其他相关配置。例如:const path = require('path');
module.exports = {
entry: './path/to/file2.js',
output: {
filename: 'bundle2.js',
path: path.resolve(__dirname, 'dist'),
},
// 其他配置项...
};
package.json
文件中,添加两个不同的打包命令,分别使用不同的Webpack配置文件。例如:{
"scripts": {
"build1": "webpack --config webpack.config1.js",
"build2": "webpack --config webpack.config2.js"
},
// 其他配置项...
}
npm run build1
将使用webpack.config1.js
来打包file1.js
,生成bundle1.js
;运行npm run build2
将使用webpack.config2.js
来打包file2.js
,生成bundle2.js
。这样,你就可以使用不同的Webpack配置文件来创建两个不同的JavaScript文件了。根据实际需求,你可以在Webpack配置文件中添加其他必要的配置项,例如加载器、插件等。
领取专属 10元无门槛券
手把手带您无忧上云