Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
168 lines (166 loc) · 6.51 KB
/
Copy pathwebpack.config.js
File metadata and controls
168 lines (166 loc) · 6.51 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const fs = require('fs');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { ProvidePlugin, DefinePlugin, IgnorePlugin } = require('webpack');
// Checkpoints a private package can fill in at build time
// (OpenConceptLab/ocl_online#465). The Dockerfile installs the package when
// PRIVATE_PACKAGES_GIT is set; without it, the open stub is used.
const PRIVATE_PACKAGE = '@openconceptlab/oclmap-extensions';
const privatePackagePath = path.resolve(__dirname, 'node_modules', ...PRIVATE_PACKAGE.split('/'));
const privatePackageAlias = fs.existsSync(privatePackagePath) ?
privatePackagePath :
path.resolve(__dirname, 'src/components/map-projects/autoMatchCheck.js');
module.exports = (env) => {
const isProduction = env.NODE_ENV === 'production';
return {
mode: env.NODE_ENV,
output: {
publicPath: '/',
// Production names carry a content hash (OpenConceptLab/ocl_issues#2824),
// so a changed bundle gets a new URL. nginx caches these files for a year
// and revalidates index.html on every load, so a returning browser never
// mixes bundles from two builds. nginx/default.conf.template matches the
// names by pattern; change the two together. Dev keeps webpack's
// defaults.
filename: isProduction ? '[name].[contenthash:8].js' : '[name].js',
chunkFilename: isProduction ? '[name].[contenthash:8].js' : '[name].js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
// The private package ships JSX source. A .babelrc doesn't reach
// files in another package, so this rule extends ours.
test: /\.(js|jsx)$/,
include: new RegExp(`node_modules[\\\\/]${PRIVATE_PACKAGE.replace('/', '[\\\\/]')}[\\\\/]`),
use: [{loader: 'babel-loader', options: {extends: path.resolve(__dirname, '.babelrc')}}],
},
{
test: /\.(png|jpg|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader'
},
{
test: /\.(scss|css)$/,
use: [{
loader: 'style-loader', // creates style nodes from JS strings
}, {
loader: 'css-loader', // translates CSS into CommonJS
}, {
loader: 'sass-loader', // compiles Sass to CSS
}],
},
],
},
optimization: isProduction ? {
splitChunks: {
chunks: 'all',
minSize: 100000,
minRemainingSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
cacheGroups: {
default: false,
vendors: false,
react: {
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom|react-router-dom)[\\/]/,
name: "react"
},
lodash: {
chunks: 'all',
test: /[\\/]node_modules[\\/](lodash)[\\/]/,
name: "lodash"
},
moment: {
chunks: 'all',
test: /[\\/]node_modules[\\/](moment|moment-timezone)[\\/]/,
name: "moment",
reuseExistingChunk: true
},
material: {
chunks: 'all',
test: /[\\/]node_modules[\\/](@material-ui[\\/]core|@material-ui[\\/]icons)[\\/]/,
name: "material",
reuseExistingChunk: true
},
materialLab: {
chunks: 'all',
test: /[\\/]node_modules[\\/](@material-ui[\\/]lab)[\\/]/,
name: "material-lab",
reuseExistingChunk: true
},
materialPickers: {
chunks: 'all',
test: /[\\/]node_modules[\\/](@material-ui[\\/]pickers)[\\/]/,
name: "material-pickers",
reuseExistingChunk: true
},
vendor: {
name: 'vendor',
chunks: 'all',
test: /[\\/]node_modules[\\/](!react)(!react-dom)(!react-router-dom)(!@material-ui)(!lodash)(!moment)(!moment-timezone)[\\/]/,
reuseExistingChunk: true,
priority: 20
}
}
}
} : {},
devServer: {
static: {
directory: path.join(__dirname, 'public')
},
historyApiFallback: {
index: '/index.html',
disableDotRule: true,
}
},
devtool: env.NODE_ENV == 'production' ? "nosources-source-map" : undefined,
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
}),
// Emits nothing today: the scss rule uses style-loader, so styles ship
// inside the JS bundles. Hashed like them in case it is ever used.
new MiniCssExtractPlugin({filename: isProduction ? '[name].[contenthash:8].css' : 'bundle.css'}),
new CopyWebpackPlugin(['src/assets']),
new ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
}),
new DefinePlugin({
'process.env.API_URL': JSON.stringify(env.API_URL),
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV) || 'development',
'process.env.GA_ACCOUNT_ID': JSON.stringify(env.GA_ACCOUNT_ID),
'process.env.HOTJAR_ID': JSON.stringify(env.HOTJAR_ID),
'process.env.ERRBIT_URL': JSON.stringify(env.ERRBIT_URL),
'process.env.ERRBIT_KEY': JSON.stringify(env.ERRBIT_KEY),
'process.env.LOGIN_REDIRECT_URL': JSON.stringify(env.LOGIN_REDIRECT_URL),
'process.env.OIDC_RP_CLIENT_ID': JSON.stringify(env.OIDC_RP_CLIENT_ID),
'process.env.OIDC_SERVER_URL': JSON.stringify(env.OIDC_SERVER_URL || ''),
'process.env.OIDC_REALM': JSON.stringify(env.OIDC_REALM || ''),
'process.env.OCL_ONLINE': JSON.stringify(env.OCL_ONLINE) || 'false',
'process.env.BRIDGE_MATCH_URL': JSON.stringify(env.BRIDGE_MATCH_URL || '') || '',
'process.env.AI_ASSISTANT_API_URL': JSON.stringify(env.AI_ASSISTANT_API_URL || '') || '',
'process.env.SCISPACY_LOINC_API_URL': JSON.stringify(env.SCISPACY_LOINC_API_URL || '') || '',
'process.env.OCL_ONLINE_API_URL': JSON.stringify(env.OCL_ONLINE_API_URL || '') || '',
'process.env.REPO_SUGGESTIONS': JSON.stringify(env.REPO_SUGGESTIONS || '')
}),
new IgnorePlugin({ resourceRegExp: /moment\/locale\// })
],
resolve: {
extensions: ['.js', '.jsx'],
alias: {
[`${PRIVATE_PACKAGE}$`]: privatePackageAlias,
},
},
};
};