-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
126 lines (115 loc) · 4.12 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
const path = require('path');
const AotPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CommonChunksPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const del = require('del');
const Dotenv = require('dotenv-webpack');
del.sync("dist/**");
module.exports = () => {
const isProd = process.argv.indexOf('-p') !== -1;
console.log(`ENV: ${isProd ? 'production' : 'development'}`);
const config = {
devtool: isProd ? false : 'inline-source-map',
resolve: { extensions: ['.ts', '.js'] },
entry: {
app: './src/main.ts',
vendor: './src/vendor.ts',
polyfills: './src/polyfills.ts'
},
output: {
filename: 'bundles/[name].[hash].bundle.js',
path: path.join(process.cwd(), "dist")
},
module: {
rules: [
{
test: /\.ts$/,
loader: '@ngtools/webpack',
options: {
tsConfigPath: './tsconfig.json'
}
},
{
test: /\.html$/,
loader: 'html-loader',
options: {
removeAttributeQuotes: false,
minimize: false
}
},
{
test: /\.(eot|svg|cur)$/,
loader: "file-loader",
options: {
name: '[name].[hash:20].[ext]',
outputPath: 'assets/'
}
},
{
test: /\.(jpg|png|webp|gif|otf|ttf|woff|woff2|ani)$/,
loader: "url-loader",
options: {
name: '[name].[hash:20].[ext]',
outputPath: 'assets/',
useRelativePath: true,
limit: 10000
}
},
{
test: /\.css$/,
include: [
path.join(__dirname, 'src/app')
],
use: [
'to-string-loader',
'css-loader'
]
},
{
test: /\.css$/,
exclude: [
path.join(__dirname, 'src/app')
],
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
}
]
},
plugins: [
new Dotenv({
path: './.env'
}),
new ProgressPlugin(),
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
}),
new ExtractTextPlugin('bundles/styles.[hash].bundle.css'),
new HtmlWebpackPlugin({
filename: __dirname + '/dist/index.html',
template: __dirname + '/src/index.html',
xhtml: true,
compile: true,
showErrors: true
}),
new CommonChunksPlugin({
names: ['app', 'vendor', 'polyfills']
})
].concat(isProd ? [
new AotPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'src/app/app.module#AppModule')
})
]:[
new ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/)
])
};
return config;
};