-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
169 lines (166 loc) · 4.46 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const rxPaths = require('rxjs/_esm5/path-mapping');
const os = require('os');
const enoughRam = os.totalmem() / 0x40000000 > 1.5;
const entryPoints = ['inline', 'sw-register', 'styles', 'vendor', 'main'];
const projectRoot = process.cwd();
// noinspection JSUnusedGlobalSymbols
module.exports = env => { // eslint-disable-line @typescript-eslint/no-unused-vars
return {
mode: (env && env.mode) === 'prod' ? 'production' : 'development',
performance: { hints: false },
target: 'web',
resolve: {
extensions: [
'.ts',
'.js'
],
symlinks: true,
modules: [
'./src',
'./node_modules'
],
alias: rxPaths(),
mainFields: ['fesm2015', 'module', 'main']
},
resolveLoader: {
modules: [
'./node_modules'
],
alias: rxPaths()
},
entry: {
main: [
'./src/main.ts'
],
styles: [
'./src/styles.css'
]
},
output: {
path: path.join(projectRoot, 'dist', 'public'),
filename: '[name].[contenthash].bundle.js',
chunkFilename: '[id].chunk.js',
crossOriginLoading: false
},
module: {
rules: [
{
test: /\.html$/i,
loader: 'raw-loader'
},
{
test: /\.(eot|svg|cur)$/i,
loader: 'file-loader',
options: {
name: '[name].[hash:20].[ext]',
limit: 10000
}
},
{
test: /\.(jpg|png|webp|gif|otf|ttf|woff|woff2|ani)$/i,
loader: 'url-loader',
options: {
name: '[name].[hash:20].[ext]',
limit: 10000
}
},
{
include: [
path.join(projectRoot, 'src/styles.css')
],
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.ts|\.tsx$/i,
use: 'ts-loader',
exclude: [/\/node_modules\//, /\/server\/(?!src\/(ntp-data|shared-types|time-poller)\.ts$).*/]
}
]
},
optimization: {
minimize: (env && env.mode) !== 'local',
minimizer: [new TerserPlugin({
terserOptions: {
output: { max_line_len: 511 }
}
})],
runtimeChunk: 'single'
},
devtool: enoughRam ? 'source-map' : undefined,
plugins: [
new CopyWebpackPlugin({
patterns: [
{
context: 'src',
to: '',
from: 'assets/**/*',
globOptions: {
dot: true,
ignore: [
'.gitkeep',
'**/.DS_Store',
'**/Thumbs.db'
],
debug: 'warning'
}
},
{
context: 'src',
to: '',
from: 'favicon.ico'
},
{
to: 'assets/',
from: 'node_modules/@tubular/astronomy/dist/resources/stars.dat'
}
]
}),
new ProgressPlugin({}),
new CircularDependencyPlugin({
exclude: /([\\/])node_modules([\\/])/,
failOnError: false,
onDetected: false,
cwd: projectRoot
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
hash: false,
inject: 'head',
compile: true,
favicon: false,
minify: false,
cache: true,
showErrors: true,
chunks: 'all',
excludeChunks: [],
title: 'Webpack App',
xhtml: true,
chunksSortMode: function sort(left, right) {
// noinspection JSUnresolvedVariable
const leftIndex = entryPoints.indexOf((left.names && left.names[0]) || left.toString());
// noinspection JSUnresolvedVariable
const rightIndex = entryPoints.indexOf((right.names && right.names[0]) || right.toString());
return Math.sign(leftIndex - rightIndex);
}
})
],
node: {
global: true
},
devServer: {
historyApiFallback: true,
proxy: {
'/assets/audio/': 'http://localhost:4201'
}
},
ignoreWarnings: [{ message: /require function is used in a way/ }]
};
};