-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
105 lines (101 loc) · 3.01 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
import * as path from 'path';
import * as webpack from 'webpack';
import * as ExtractTextPlugin from 'extract-text-webpack-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 {AotPlugin} from '@ngtools/webpack';
export default (environment: string) => {
const {ifProduction, ifDevelopment} = getIfUtils(environment);
const outputFilename = ifProduction('[name]-[chunkhash]', '[name]');
const extractCSS = new ExtractTextPlugin(`${outputFilename}.css`);
const PROD_PUBLIC_PATH = '/angular2-tv-tracker/';
return {
devtool: ifProduction('source-map', 'eval'),
entry: './src/entry.ts',
output: {
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$/,
loader: extractCSS.extract(['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'
}])
},
resolve: {
extensions: ['.ts', '.js']
},
devServer: {
port: 8000,
inline: true
},
plugins: removeEmpty([
ifDevelopment(new ForkTsCheckerWebpackPlugin()),
ifProduction(new AotPlugin({
tsConfigPath: './tsconfig-aot.json'
})),
ifProduction(new webpack.optimize.UglifyJsPlugin({sourceMap: true})),
new webpack.DefinePlugin({
ENV: JSON.stringify(environment)
}),
extractCSS,
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
__dirname + '/src'
),
new webpack.optimize.CommonsChunkPlugin({
name: 'main',
async: true,
minChunks: 2
}),
new HtmlWebpackPlugin({
template: 'src/index.ejs',
title: 'Angular 2+ TV tracker'
}),
ifProduction(new webpack.optimize.ModuleConcatenationPlugin()),
ifProduction(new OfflinePlugin({
ServiceWorker: {
navigateFallbackURL: PROD_PUBLIC_PATH
}
}))
])
};
};