-
Notifications
You must be signed in to change notification settings - Fork 4
/
app-factory.js
94 lines (89 loc) · 2.83 KB
/
app-factory.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
91
92
93
94
const webpack = require('webpack');
const log = new (require("chillogger"))("app-factory");
const HtmlWebpackPlugin = require('html-webpack-plugin');
process.env.NODE_ENV = process.env.NODE_ENV || "development"
const { join } = require("path");
function getCompilerConfig() {
const config = {
optimization: {
minimize: false,
},
entry: {
malwindow: join(__dirname, "src/malwindow.js"),
agent: join(__dirname, "src/agent.js"),
},
output: {
filename: '[name].js',
path: join(__dirname, "dist"),
chunkFilename: '[name].bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
"sourceType": "unambiguous",
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-react-jsx",
]
}
}
},
{
test: /\.scss$/,
use: [
{
loader: "style-loader" // creates style nodes from JS strings
},
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "sass-loader" // compiles Sass to CSS
}
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
hot: true,
},
plugins: [
new HtmlWebpackPlugin({
chunks: ["malwindow"],
template: "src/malwindow.ejs",
filename: 'index.html'
}),
new webpack.SourceMapDevToolPlugin({})
]
}
return config
}
const compilerDone = (err, stats) => {
const { errors, missingDependencies } = stats.compilation;
if (errors.length) {
return errors.forEach(error => log.warn(`got an error when compiling: ${error.message}`, error.stack))
}
log.info(`app build ${stats.hash} completed`)
}
module.exports = (watch) => {
const compiler = webpack(getCompilerConfig());
if (watch) {
log.info("In dev mode. Starting watcher")
compiler.watch({
aggregateTimeout: 300,
poll: undefined
}, compilerDone)
} else {
compiler.run(compilerDone)
}
}