-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
117 lines (104 loc) · 2.84 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { AureliaPlugin } = require('aurelia-webpack-plugin');
let srcDir = path.resolve(__dirname, 'src');
let distDir = path.resolve(__dirname, 'dist');
let assetsDir = path.resolve(__dirname, 'assets');
function configure(env, args) {
let mode = args.mode;
let production = mode === 'production';
let styleLoaders = [
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
loader: 'resolve-url-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
];
let config = {
entry: {
app: 'aurelia-bootstrapper'
},
output: {
path: distDir,
filename: production ? '[name]-[hash].js' : '[name].js',
chunkFilename: production ? '[name]-[hash].js' : '[name].js'
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader'
},
{
test: /\.html$/,
use: 'html-loader'
},
{
test: /\.scss$/,
use: [
production ? MiniCssExtractPlugin.loader : 'style-loader',
...styleLoaders
]
},
{
test: /\.(png|jpg|gif)$/,
use: 'file-loader?name=images/[name]-[hash].[ext]'
}
]
},
resolve: {
extensions: [
'.js',
'.ts'
],
modules: [
'node_modules',
srcDir
]
},
plugins: [
new AureliaPlugin(),
new HtmlWebpackPlugin({
template: 'index.ejs',
favicon: path.resolve(assetsDir, 'favicon.ico')
})
],
devServer: {
stats: 'errors-only'
}
};
switch (args.mode) {
case 'development':
config.devtool = 'inline-source-map';
break;
case 'production':
config.plugins.push(new MiniCssExtractPlugin({
filename: '[name]-[hash].css',
chunkFilename: '[name]-[hash].css'
}));
break;
}
return config;
}
module.exports = configure;