-
Notifications
You must be signed in to change notification settings - Fork 26
/
webpack.config.ts
134 lines (132 loc) · 3.66 KB
/
webpack.config.ts
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
import * as path from 'path';
import * as webpack from 'webpack';
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as OfflinePlugin from 'offline-plugin';
import * as ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import { getIfUtils, removeEmpty } from 'webpack-config-utils';
import { AngularCompilerPlugin } from '@ngtools/webpack';
export default (environment: string) => {
const { ifProduction, ifDevelopment } = getIfUtils(environment);
const outputFilename = ifProduction('[name]-[chunkhash]', '[name]');
const PROD_PUBLIC_PATH = '/angular2-tv-tracker/';
return {
mode: environment,
entry: './src/entry.ts',
output: {
path: __dirname,
filename: `${outputFilename}.js`,
publicPath: ifProduction(PROD_PUBLIC_PATH, '/')
},
module: {
rules: removeEmpty([
ifDevelopment({
test: /\.ts$/,
loader: 'tslint-loader',
exclude: /node_modules/,
enforce: 'pre',
options: {
emitErrors: false,
failOnHint: false
}
}),
ifProduction(
{
test: /\.ts$/,
loader: '@ngtools/webpack'
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
compilerOptions: {
module: 'es2015'
}
}
},
{
loader: 'angular-router-loader'
}
],
exclude: path.resolve(__dirname, 'node_modules')
}
),
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader?minimize',
'sass-loader'
]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
},
{
test: /node_modules\/@angular\/core\/.+\/core\.js$/,
parser: {
system: true // disable `System.import() is deprecated and will be removed soon. Use import() instead.` warning
}
}
])
},
resolve: {
extensions: ['.ts', '.js']
},
devServer: {
port: 8000,
inline: true
},
plugins: removeEmpty([
ifDevelopment(new ForkTsCheckerWebpackPlugin()),
ifProduction(
new AngularCompilerPlugin({
tsConfigPath: './tsconfig-aot.json'
})
),
new MiniCssExtractPlugin({
filename: `${outputFilename}.css`
}),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)fesm5/,
__dirname + '/src'
),
new HtmlWebpackPlugin({
template: 'src/index.ejs',
title: 'Angular 2+ TV tracker',
chunksSortMode: 'none'
}),
ifProduction(
new OfflinePlugin({
ServiceWorker: {
navigateFallbackURL: PROD_PUBLIC_PATH
}
})
)
]),
optimization: {
splitChunks: ifProduction(
{
chunks: 'all',
automaticNameDelimiter: '.'
},
false
),
runtimeChunk: ifProduction(true, false),
removeAvailableModules: ifProduction(true, false), // disable tree shaking in dev mode for faster rebuilds
removeEmptyChunks: ifProduction(true, false)
}
};
};