Repository navigation
Expand file tree
/
Copy pathwebpack.common.js
More file actions
112 lines (107 loc) · 2.51 KB
/
Copy pathwebpack.common.js
File metadata and controls
112 lines (107 loc) · 2.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
const path = require('path');
const DotenvWebpackPlugin = require('dotenv-webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { compilerOptions } = require('./tsconfig.json');
const {
PROJECT_FOLDER,
ENTRY_FILE_NAME,
PUBLIC_PATH,
PUBLIC_FOLDER,
BUILD_WEB_FOLDER,
TEMPLATE_FILE,
OUTPUT_PATH
} = require('./webpack.config');
const plugins = [
new DotenvWebpackPlugin({
path: path.resolve(PROJECT_FOLDER, '.env'),
safe: false,
systemvars: true
}),
new CopyWebpackPlugin({
patterns: [
{
from: PUBLIC_FOLDER,
to: BUILD_WEB_FOLDER,
globOptions: {
ignore: ['**/index.html'],
logLevel: 'info'
},
noErrorOnMissing: true
}
]
}),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [path.join(BUILD_WEB_FOLDER, '**/*'), '!**/*.gitignore']
}),
new HtmlWebpackPlugin({
template: TEMPLATE_FILE,
filename: '../index.html',
hash: false,
minify: {
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true
}
})
];
const moduleRules = [
{
test: /\.(js|jsx|ts|tsx)$/,
use: {
loader: 'babel-loader'
},
exclude: /node_modules/
}
];
const alias = Object.keys(compilerOptions.paths).reduce((result, key) => {
result[key.replace('/*', '')] = path
.resolve(PROJECT_FOLDER, compilerOptions.paths[key][0])
.replace('/*', '');
return result;
}, {});
module.exports = {
name: 'web',
target: 'web',
entry: ENTRY_FILE_NAME,
output: {
crossOriginLoading: 'anonymous',
path: OUTPUT_PATH,
publicPath: PUBLIC_PATH
},
plugins,
module: {
rules: moduleRules
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
alias: alias
},
optimization: {
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
reactDom: {
test: /[\\/]node_modules[\\/]react-dom[\\/]/,
name: 'vendor1',
chunks: 'all'
},
materilUi: {
test: /[\\/]node_modules[\\/]@material-ui[\\/]/,
name: 'vendor2',
chunks: 'all'
},
firebase: {
test: /[\\/]node_modules[\\/]@firebase[\\/]/,
name: 'vendor3',
chunks: 'all'
}
}
}
}
};