-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
139 lines (134 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
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
const webpack = require('webpack');
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const dotenv = require('dotenv');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// Set up environment variables.
const result = dotenv.config();
// Prevent other keys from leaking into the app by defining allowed keys.
const allowedKeys = [
'INTERCOM_APP_ID',
'SENTRY_PUBLIC_DSN',
'SEGMENT_WRITE_KEY',
'DEBUG',
'BASE_URL',
'SOCKET_BASE',
'SENTRY_DSN'
];
const env = result.error ? process.env : result.parsed;
const envKeys = Object.keys(env).reduce((acc, next) => {
if (allowedKeys.includes(next)) {
acc[`process.env.${next}`] = JSON.stringify(env[next]);
}
return acc;
}, {});
module.exports = {
output: {
publicPath: '/',
chunkFilename: '[chunkhash].js'
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
}
}
}
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
minimize: true
}
}
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[hash].[ext]'
}
}
]
},
{
test: /favicon\.ico$/,
loader: 'url',
query: {
limit: 1,
name: '[name].[ext]'
}
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.scss$/,
use: [
'style-loader', // creates style nodes from JS strings
'css-loader', // translates CSS into CommonJS
'sass-loader' // compiles Sass to CSS, using Node Sass by default
]
}
]
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.jsx'],
alias: {
src: path.resolve(__dirname, 'src/'),
style: path.resolve(__dirname, 'src/sass/'),
pages: path.resolve(__dirname, 'src/components/pages/'),
components: path.resolve(__dirname, 'src/components/'),
models: path.resolve(__dirname, 'src/models/'),
utils: path.resolve(__dirname, 'src/utils/'),
lib: path.resolve(__dirname, 'src/lib/'),
images: path.resolve(__dirname, 'src/images/')
}
},
devServer: {
historyApiFallback: true
},
plugins: [
new HtmlWebPackPlugin({
template: 'src/index.html',
filename: './index.html'
}),
new webpack.HashedModuleIdsPlugin(),
new webpack.DefinePlugin(envKeys),
new CopyWebpackPlugin(['./_redirects', './favicon.ico']),
// TODO: Can be removed once Froala releases jQuery-less version.
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
};