-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (105 loc) · 3.32 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const buildDate = new Date().valueOf();
module.exports = {
devtool: 'sourcemap',
devServer: { historyApiFallback: true },
entry: [
'@babel/polyfill',
'core-js/fn/array/flat-map',
'bootstrap-loader',
'react-hot-loader/patch',
'webpack/hot/only-dev-server',
'whatwg-fetch',
'./app/index.development.js',
],
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '/',
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.(ts|tsx|js)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [
{ loader: 'style-loader', options: { sourceMap: true } },
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
],
},
{
test: /\.scss$/,
use: [
{ loader: 'style-loader', options: { sourceMap: true } },
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
],
},
{
test: /\.woff?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff&name=[path][name].[ext]',
},
{
test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff2&name=[path][name].[ext]',
},
{
test: /\.(eot|ttf|svg|gif|png|jpg)(\?[\s\S]+)?$/,
loader: 'file-loader',
},
],
},
resolve: {
modules: [path.resolve(__dirname, 'node_modules'), path.resolve(__dirname, 'app'), 'node_modules'],
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
moment$: 'moment/moment.js',
'react-dom': '@hot-loader/react-dom',
},
},
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('@', '')}`;
},
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.html',
filename: 'index.html',
chunksSortMode: 'none',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.buildDate': buildDate,
'process.env.DEV_LOGIN': JSON.stringify(process.env.DEV_LOGIN),
'process.env.DEV_PASS': JSON.stringify(process.env.DEV_PASS),
}),
new FaviconsWebpackPlugin('./favicon.png'),
new GenerateJsonPlugin('version.json', { buildDate }),
],
};