forked from acao/webpack-web-and-electron-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
48 lines (42 loc) · 1.24 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint strict: 0 */
'use strict';
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const [,,command, value] = process.argv;
const srcPath = path.join(__dirname, 'src');
const isWeb = (process.env.APP_TARGET && process.env.APP_TARGET === 'WEB');
const outputPath = path.join(__dirname, 'build', isWeb ? 'web' : 'electron');
const indexPath = path.join(outputPath, isWeb ? 'index.html' : 'index-electron.html');
console.log({ outputPath, indexPath, isWeb })
let options = {
mode: process.env.NODE_ENV,
module: {
rules: [{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
// plugins: [require('@babel/plugin-proposal-object-rest-spread')]
}
},
exclude: [ /node_modules/ ],
}]
},
devServer: {
contentBase: outputPath,
},
output: {
path: outputPath,
filename: 'bundle.js',
},
entry: './src/index',
plugins: [new HtmlWebpackPlugin({
title: `My ${isWeb ? 'Web' : 'Electron'} App`,
template: path.join(srcPath, 'index.html'),
filename: indexPath,
})]
};
options.target = isWeb ? 'web' : 'electron-renderer'
module.exports = options;