-
Notifications
You must be signed in to change notification settings - Fork 29
/
webpack.config.js
81 lines (78 loc) · 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
const path = require('path');
const fs = require('fs');
const { join } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const standalone = process.env.STANDALONE === '1';
const production = process.env.MODE === 'production';
const constants = {};
if (standalone) {
const constantPrefix = 'VIZ_';
for (const key of Object.keys(process.env).filter(k => k.startsWith(constantPrefix))) {
const value = process.env[key];
const name = key.slice(constantPrefix.length);
try {
constants[name] = JSON.parse(fs.readFileSync(value, 'utf-8'));
} catch {
constants[name] = JSON.parse(value);
}
}
}
module.exports = (dirname, file = 'client') => ({
mode: production ? 'production' : 'development',
devtool: production ? false : 'inline-source-map',
entry: `./src/client/client.tsx`,
output: {
jsonpFunction: path.dirname(dirname).replace(/[^a-z]/gi, ''),
path: path.join(dirname, 'out'),
filename: `${file}.bundle.js`,
publicPath: 'http://localhost:8116/'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.svg', '.vert', '.frag'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: { configFile: 'tsconfig.browser.json' },
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
},
},
'postcss-loader',
],
},
{
test: /\.svg$/,
loader: 'svg-inline-loader',
},
{
test: /\.(vert|frag)$/,
loader: 'raw-loader',
},
],
},
devServer: {
allowedHosts: ['null'],
headers: {
'Access-Control-Allow-Origin': '*'
}
},
plugins: standalone
? [
new HtmlWebpackPlugin({
template: join(__dirname, '..', 'samples/index.ejs'),
templateParameters: { constants },
}),
]
: [],
});