-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
117 lines (105 loc) · 3.2 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const path = require('path');
const merge = require('lodash/merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const config = {
entry: './src/index.ts',
devServer: {
contentBase: './wallpaper',
hot: true,
// see https://webpack.js.org/configuration/dev-server/#devserverbefore
before(app) {
// handle the transfer of Wallpaper Engine properties
// see "/assets/bridge.html"
// I MUST BE CRAZY TO DO THIS
const props = {
userProps: {},
generalProps: {},
files: {},
};
// receive properties by POST
app.post('/props', require('body-parser').json(), (req, res, next) => {
// save props to local variables
merge(props.userProps, req.body.userProps);
merge(props.generalProps, req.body.generalProps);
// DON'T use merge on files because merging will keep the removed files!
Object.assign(props.files, req.body.files);
res.json(props);
});
// return properties by GET
app.get('/props', (req, res, next) => {
res.json(props);
});
},
after(app) {
// override default 404 behaviour so it won't send us an HTML 404 page
app.use((req, res, next) => {
res.status(404).end();
});
},
},
module: {
rules: [
{
test: /\.[jt]s$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader',
],
},
{
test: /\.(vert|frag)$/,
use: [
'raw-loader',
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.js'],
},
output: {
publicPath: '', // use empty path to make generated files be able to load by 'file://' scheme
filename: '[name].[hash:4].js',
path: path.resolve(__dirname, 'dist'),
},
optimization: {
minimize: false,
},
};
module.exports = (env, argv) => {
config.mode = argv.mode;
if (argv.mode === 'development') {
config.devtool = 'inline-source-map';
}
return config;
};