-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
96 lines (91 loc) · 1.93 KB
/
webpack.config.js
File metadata and controls
96 lines (91 loc) · 1.93 KB
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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const path = require('path');
let devTool;
const isDev = process.env.NODE_ENV !== 'production';
const entry = [
'./src/index.tsx',
];
const plugins = [
new HtmlWebpackPlugin({
template: './src/index.ejs',
title: 'Dataset Statistics',
}),
new MiniCssExtractPlugin({
filename: 'styles.[hash].css',
}),
];
const rules = [
{
exclude: /(node_modules)/,
test: /\.(t|j)sx?$/,
use: [
{
loader: 'ts-loader',
},
],
},
{
exclude: /(nothing)/, // NOTE: To work around TypeScript issue
test: /\.css$/,
use: [
'style-loader',
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false
}
},
'css-loader',
],
},
];
if (isDev) {
devTool = 'source-map';
// Source maps are generated by tsc (the TypeScript compiler rather than by Webpack so it
// is necessary to load them for development purposes...
rules.push({
exclude: /(node_modules)/,
test: /\.js$/,
use: ['source-map-loader'],
});
} else {
plugins.push(new OptimizeCssAssetsPlugin({
cssProcessorOptions: { discardComments: { removeAll: true } },
}));
}
module.exports = {
context: __dirname,
devServer: {
contentBase: './',
historyApiFallback: true,
https: true,
port: 3000,
},
devtool: devTool,
entry,
externals: {
fs: '{}',
},
mode: isDev ? 'development' : 'production',
module: {
rules,
},
optimization: {
noEmitOnErrors: true,
},
output: {
filename: 'bundle.[hash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
plugins,
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
modules: [
path.resolve('./node_modules'),
],
},
target: 'web',
};