-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
webpack.config.js
88 lines (87 loc) · 3.3 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = function (env) {
const production = env === 'production';
const plugins = [
new WebpackManifestPlugin(),
new MiniCssExtractPlugin({
filename: production ? '[name].[chunkhash].css' : '[name].css',
chunkFilename: production ? '[name].[chunkhash].css' : '[name].css'
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
mode: "write-references",
},
eslint: {
files: "scripts/**/*.{ts,tsx,js,jsx}",
options: { fix: !production },
},
}),
new CleanWebpackPlugin()
]
return {
context: path.resolve(__dirname, 'webserver', 'static'),
entry: {
common: ['./scripts/common.ts'],
datasets: ['./scripts/datasets.tsx'],
similarity: ['./scripts/similarity.ts'],
homepage: ['./scripts/homepage.ts'],
profile: ['./scripts/profile.ts'],
stats: ['./scripts/stats.ts'],
highlight: ['./scripts/highlight.ts'],
main: ['./styles/main.less'],
},
output: {
chunkFilename: production ? '[name].[chunkhash].js' : '[name].js',
filename: production ? '[name].[chunkhash].js' : '[name].js',
path: path.resolve(__dirname, 'webserver', 'static', 'build'),
publicPath: '/static/build/'
},
mode: production ? 'production' : 'development',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
}
],
},
{
test: /\.less$/,
use: [
{loader: MiniCssExtractPlugin.loader},
{loader: 'css-loader'},
{
loader: 'less-loader',
// Set 'paths' to use the less resolver not the webpack one
// https://www.npmjs.com/package/less-loader#less-resolver
// Fixes issue where we @import url(https://googlefont)
options: {
paths: [path.resolve(__dirname, 'node_modules')],
}
}
]
}
],
},
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
plugins
}
};