-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (83 loc) · 2.51 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
import { resolve } from 'path';
import { AngularWebpackPlugin } from "@ngtools/webpack";
import linkerPlugin from "@angular/compiler-cli/linker/babel";
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts';
const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';
export default {
mode: mode,
entry: {
main: './src/main.ts',
styles: './styles/styles.scss',
},
output: {
path: resolve("./www/assets"),
publicPath: "/assets/", // Only needed for the webpack dev server
filename: isProduction ? "[name].[contenthash].js" : "[name].js",
// Clean folder after every build
clean: true
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
// Note: Angular component (S)CSS files need to be returned as strings by the loader as that is what the Angular compiler expects.
// Because of this, we have two (S)CSS loaders here: One for Angular components styles and one for all other styles.
// We differentiate them by the convention that Angular component style files must always end with ".component.(s)css"
// Parses normal style files, outputs the contents in a separate CSS file
{
test: /\.(s[ac]|c)ss$/,
exclude: /\.component\.(s[ac]|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
// Parses Angular component style files
{
test: /\.component\.(s[ac]|c)ss$/,
use: [
{
loader: 'css-loader',
options: {
exportType: 'string'
},
},
'sass-loader'
],
},
// Angular loaders for webpack: Parses normal Typescript as well as Angular components
{
test: /\.[jt]sx?$/,
loader: "@ngtools/webpack",
},
{
test: /\.[cm]?js$/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true,
compact: true,
plugins: [linkerPlugin],
},
},
},
],
},
optimization: {
usedExports: true,
},
plugins: [
new AngularWebpackPlugin({
tsconfig: "./tsconfig.json"
}),
// Removes empty leftover js files from MiniCssExtractPlugin
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
filename: isProduction ? "[name].[contenthash].css" : '[name].css'
})
]
};