This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack_common_config.js
102 lines (85 loc) · 2.7 KB
/
webpack_common_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
// COMMON WEBPACK ENVIRONMENT
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
let pathsToClean = ['dist'];
let cleanOptions =
{
root: ('./dist'),
verbose: true
}
module.exports = function(env) {
return {
entry: {
polyfills: './polyfills.ts',
app: './main.ts'
},
output: {
filename: '[name].js',
path: root('./dist'),
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css']
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: __dirname + /node_modules/,
loader: 'awesome-typescript-loader'
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'file-loader?emitFile=false&name=[path][name].[ext]',
options: {
limit: 10000
}
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract(
{
fallback: 'style-loader',
use: 'css-loader',
}
)
},
{
test: /\.html$/,
use: [{
loader: 'html-loader'
}]
}
]
},
plugins: [
new CleanWebpackPlugin(pathsToClean, cleanOptions),
new webpack.ContextReplacementPlugin(
// Angular5 - Webpack build workaround
/angular(\\|\/)core(\\|\/)/,
root('./application'),
{}
),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new ExtractTextPlugin({
filename: 'styles.bundle.css',
allChunks: true
}),
new HtmlWebpackPlugin({
files: {
"css" : ["styles.bundle.css"]
},
hash: true,
inject: 'body',
cache: false,
template: './my-index.ejs'
})
]
}
}
function root(__path) {
return path.join(__dirname, __path);
}