-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
65 lines (59 loc) 路 1.61 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
const createFileRule = require('@moped/rule-file');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {join} = require('path');
// serve some assets up separately to create cross domain
// issue
const {createServer} = require('http');
const finalhandler = require('finalhandler');
const serveStatic = require('serve-static');
const serve = serveStatic(__dirname + '/assets');
const server = createServer((req, res) => {
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS, GET',
// 'Access-Control-Max-Age': 2592000, // 30 days
/** add other headers as per requirement */
};
if (req.method === 'OPTIONS') {
res.writeHead(204, headers);
res.end();
return;
}
if (['GET'].indexOf(req.method) !== -1) {
Object.keys(headers).forEach((key) => {
res.setHeader(key, headers[key]);
});
serve(req, res, finalhandler(req, res));
return;
}
res.writeHead(405, headers);
res.end(`${req.method} is not allowed for the request.`);
});
server.listen(3001);
module.exports = {
entry: join(__dirname, 'src', 'demo', process.env.DEMO ? process.env.DEMO + '.ts' : 'mouse.ts'),
target: 'node',
output: {
path: __dirname + '/lib',
publicPath: '/',
},
module: {
rules: [
{
oneOf: [
{
test: /\.tsx?$/,
exclude: [/node_modules/],
use: [{loader: 'ts-loader'}],
},
createFileRule(),
],
},
],
},
mode: 'development',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
plugins: [new HtmlWebpackPlugin()],
};