Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
158 lines (157 loc) · 5.41 KB
/
Copy pathwebpack.config.js
File metadata and controls
158 lines (157 loc) · 5.41 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
const path = require('path');
const fs = require('fs');
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');
module.exports = (env) => {
const isProduction = env.NODE_ENV === 'production';
const analyticsPluginModulePath = path.resolve(__dirname, 'node_modules', 'ocl-analytics-web');
const analyticsPluginAlias = fs.existsSync(analyticsPluginModulePath) ?
analyticsPluginModulePath :
path.resolve(__dirname, 'src/common/plugins/usage-dashboard.stub.js');
return {
mode: env.NODE_ENV,
// Production bundle names carry a content hash, so a deploy that changes
// a bundle also changes its URL and nginx can cache the bundles for a
// year (nginx/default.conf.template). HtmlWebpackPlugin writes the hashed
// names into index.html. Dev keeps webpack's default [name].js / [id].js.
output: isProduction ? {
publicPath: '/',
filename: '[name].[contenthash:8].js',
chunkFilename: '[name].[contenthash:8].js',
} : {
publicPath: '/',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
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.resolve(__dirname, 'public'),
},
allowedHosts: 'all',
historyApiFallback: {
index: '/index.html',
disableDotRule: true,
},
proxy: [
{
context: ['/api'],
target: 'https://openconceptlab.org',
changeOrigin: true,
pathRewrite: { '^/api': '' },
},
],
},
devtool: env.NODE_ENV == 'production' ? "source-map" : "cheap-module-source-map",
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
}),
new MiniCssExtractPlugin({filename: '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.RECAPTCHA_SITE_KEY': JSON.stringify(env.RECAPTCHA_SITE_KEY || ''),
'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.ANALYTICS_API': JSON.stringify(env.ANALYTICS_API || ''),
'process.env.AI_ASSISTANT_API_URL': JSON.stringify(env.AI_ASSISTANT_API_URL || ''),
}),
new IgnorePlugin({ resourceRegExp: /moment\/locale\// })
],
resolve: {
extensions: ['.js', '.jsx'],
alias: {
'ocl-analytics-web$': analyticsPluginAlias,
},
},
};
};