-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
106 lines (102 loc) · 3.47 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const { EnvironmentPlugin } = require('webpack');
const isProd = process.env.NODE_ENV === 'production';
const config = {
context: path.resolve(__dirname, 'home/javascript'),
devtool: isProd ? false : 'eval-cheap-module-source-map',
mode: isProd ? 'production' : 'development',
entry: {
bootstrap: './bootstrap/index.js',
curation: './curation/index.js',
'jquery-ui': './jquery-ui/index.js',
profiles: './profiles/index.js',
search: './search/index.js',
style: './style/index.js',
react: './react/index.js',
'vendor-common': './vendor-common/index.js',
'zfin-common': './zfin-common/index.js',
},
output: {
path: path.resolve(process.env.TARGETROOT, 'home/dist'),
filename: '[name].[contenthash].js',
publicPath: '/dist/'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.tsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript']
}
},
exclude: /node_modules/
},
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
additionalData: `$primary: ${process.env.PRIMARY_COLOR || 'null'};`
}
}
]
},
{
//old method was supposed to inline any assets smaller than 8k as base64 data-uris
//new method: https://stackoverflow.com/a/67514465
test: /\.(woff2?|ttf|eot|svg|gif|png)$/,
type: 'asset/resource'
},
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].bundle.[contenthash].css'
}),
new WebpackAssetsManifest({
output: '../asset-manifest.json', // relative to output.path
publicPath: true,
}),
new HtmlWebpackPlugin(),
// expose certain environment variables via process.env
new EnvironmentPlugin([
'NODE_ENV',
'WIKI_HOST',
'ZFIN_ADMIN'
]),
],
optimization: {
minimize: isProd,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
// jquery is loaded via CDN to make bootstrap 4 play nicely with inline script tags
externals: {
jquery: 'jQuery'
},
};
module.exports = config;