-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
32 lines (29 loc) · 841 Bytes
/
webpack.config.js
File metadata and controls
32 lines (29 loc) · 841 Bytes
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
var fs = require('fs');
var bodyParser = require('body-parser');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var isProd = process.env.ENV === 'prod';
module.exports = {
mode: isProd ? 'production' : 'development',
entry: './src/index.js',
output: {
path: __dirname + '/docs',
filename: 'main.js'
},
devtool: isProd ? '' : 'cheap-eval-source-map',
plugins: [new HtmlWebpackPlugin({
template: './src/index.html'
})],
devServer: {
before: (app, server) => {
app.use(bodyParser.json());
app.post('/levels', (req, res) => {
try {
fs.writeFileSync('./src/levels.json', JSON.stringify(req.body, null, 2) + '\n', 'utf8');
res.json({ message: 'Levels exported' });
} catch (err) {
res.json({ message: 'Error' });
}
})
}
}
};