-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (95 loc) · 2.9 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
'use strict';
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
// variables
const outPath = path.join(__dirname, 'dist');
//plugins
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const entryConfig = {
app: ['@babel/polyfill', 'react-hot-loader/patch', './src/index.tsx']
};
const baseConfig = {
mode: 'development',
devtool: 'source-map',
entry: entryConfig,
module: {
rules: [
{ test: /\.ts(x?)$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.(woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
]
},
output: {
path: outPath,
filename: 'static/[name].js',
chunkFilename: 'static/[name].[contentHash].js',
publicPath: '/'
},
target: 'web',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
// Fix webpack's default behavior to not load packages with jsnext:main module
// (jsnext:main directs not usually distributable es6 format, but es6 sources)
mainFields: ['module', 'browser', 'main'],
plugins: [new TsconfigPathsPlugin()]
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
favicon: './public/favicon.ico'
}),
new webpack.DefinePlugin({
ROOT: JSON.stringify('/'),
API_URL: JSON.stringify('http://localhost:6401/')
}),
new CopyWebpackPlugin([
{ from: 'public/manifest.json', to: '' },
{ from: 'public/translations.json', to: 'static' },
{ from: 'src/assets', to: 'assets' }
])
],
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
},
port: 4100
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
chunks: 'all',
test: /[\\/]node_modules[\\/]/,
priority: 20
},
common: {
name: 'common',
minChunks: 2,
chunks: 'async',
priority: 10,
reuseExistingChunk: true,
enforce: true
}
}
},
minimize: false,
runtimeChunk: false
}
};
module.exports = (env, argv) => {
env = env || {};
let environment = (process.env.APP_ENV || 'development').toLowerCase();
if (environment === 'production') {
return merge.smartStrategy({ plugins: 'replace' })(baseConfig, require('./webpack.config.production.js').apply(this, [env, argv]));
}
if (environment === 'demo') {
return merge.smartStrategy({ plugins: 'replace' })(baseConfig, require('./webpack.config.demo.js').apply(this, [env, argv]));
}
return baseConfig;
};