一旦我开始使用webpack,我就一直在用电子非常艰难。
这是我的配置:
module.exports = function (env) {
return {
devtool: 'cheap-module-source-map',
entry: {
background: './src/electron/background/index.js',
app: './src/electron/app/index.js'
},
output: {
path: path.join(__dirname, '../dist/electron'),
filename: '[name]/index.bundle.js'
},
resolve: {
extensions: ['.js']
},
module: {
loaders: [
{ test:/\.css$/, exclude:/node_modules/, use:['style-loader', 'css-loader'] },
{ test:/\.js$/, exclude:/node_modules/, loader:'babel-loader' }
]
},
target: 'electron',
}
}
我有两个捆绑包,一个是background
,另一个是app
。 background
目标为electron-main
,而app
为electron-renderer
。但是我只能在配置中设置一个目标。如何根据捆绑设置不同的目标?
感谢你
答案 0 :(得分:1)
只需将其键入为数组
const path = require('path');
var webpack_config = [
{
entry: path.join(__dirname, "src", "js", "main.js"),
output: {
path: path.join(__dirname, "build"),
filename: "main.js"
},
target: "electron-main",
},
{
entry: path.join(__dirname, "src", "js", "renderer.js"),
output: {
path: path.join(__dirname, "build"),
filename: "renderer.js"
},
target: "electron-renderer"
}
];
module.exports = webpack_config;
https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations