-
Notifications
You must be signed in to change notification settings - Fork 181
/
webpack.config.js
90 lines (76 loc) · 2.38 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const argv = require('optimist').argv;
let entry = [
'babel-polyfill',
'./src/client/index'
];
let plugins = [];
let devtool = 'eval-source-map';
let output = 'static/js/index.js';
let debug = true;
let PLATFORM = argv.platform || 'web';
let NODE_ENV = argv.build ? 'production' : 'development';
let target = 'web';
if (PLATFORM === 'electron') target = 'electron-renderer';
plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
'PLATFORM': JSON.stringify(PLATFORM)
}));
if (argv.build) {
let outputDir;
if (PLATFORM === 'web') {
outputDir = 'web/';
}
if (PLATFORM === 'electron') {
outputDir = '../electron/www/';
}
plugins.push(new CopyWebpackPlugin([{from: 'src/client/resources', to: outputDir}]));
devtool = false;
output = outputDir + 'static/js/index.js';
debug = false;
}
else {
entry.push('webpack-dev-server/client?http://localhost:4000');
plugins.push(new CopyWebpackPlugin([{from: 'src/client/resources', to: './'}]));
}
let config = {
entry: entry,
output: {
path: __dirname + "/dist",
filename: output
},
devtool: devtool,
target: target,
mode: NODE_ENV,
module: {
noParse: /.*[\/\\]bin[\/\\].+\.js/,
rules: [
{
test: /.jsx?$/,
include: [path.resolve(__dirname, 'src')],
use: [{loader: 'babel-loader', options: {presets: ['@babel/preset-react', '@babel/preset-env']}}]
},
{
test: /\.js$/,
include: [path.resolve(__dirname, 'src')],
use: [{loader: 'babel-loader', options: {presets: ['@babel/preset-env']}}]
},
{
test: /\.(html|htm)$/,
use: [{loader: 'dom'}]
}
]
},
optimization: {
minimize: false
},
plugins: plugins
};
if (target === 'electron-renderer') {
config.resolve = {alias: {'platform': path.resolve(__dirname, './src/client/platform/electron')}};
} else {
config.resolve = {alias: {'platform': path.resolve(__dirname, './src/client/platform/web')}};
}
module.exports = config;