This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
128 lines (110 loc) · 3.17 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
127
128
/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require('@artonge/webpack');
// const ngcWebpack = require("ngc-webpack");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const DefinePlugin = require('webpack').DefinePlugin;
const AngularCompilerPlugin = webpack.AngularCompilerPlugin;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const _root = path.resolve(__dirname, '.');
function getRoot(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
}
module.exports = function(env, argv) {
return {
mode: env.production ? 'production' : 'development',
entry: {
coliseum: './src/js/modules/app/main.ts',
loader: './src/js/modules/loader/main.ts',
},
target: 'web',
devtool: env.production ? false : 'inline-source-map',
optimization: env.production
? {
minimize: true,
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true, // Must be set to true if using source-maps in production
terserOptions: {
mangle: false,
keep_classnames: true,
keep_fnames: true,
},
}),
],
namedModules: true,
namedChunks: true,
}
: {},
// watch: false,
// watchOptions: {
// ignored: ['node_modules'],
// },
output: {
path: getRoot('dist'),
publicPath: '/',
filename: '[name].js',
},
resolve: {
// Having ts before js is important for webpack watch to work
// However, angular2-indexeddb creates an issue (ts files are packaged alongside js), so
// you need to remove the .ts files from its node_modules folder
// See https://github.com/gilf/angular2-indexeddb/issues/67
extensions: ['.ts', '.js', '.html'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: ['@artonge/webpack', 'eslint-loader'],
},
{
test: /.js$/,
parser: {
system: true,
},
},
{
test: /\.scss$/,
include: getRoot('src', 'css'),
use: ['raw-loader', 'sass-loader'],
},
{
test: /\.scss$/,
exclude: getRoot('src', 'css'),
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
plugins: [
new DefinePlugin({
'process.env.APP_VERSION': JSON.stringify(env.appversion),
}),
new AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModules: [
'./src/js/modules/app/app.module#AppModule',
'./src/js/modules/loader/loader.module#LoaderModule',
],
sourceMap: true,
}),
new MiniCssExtractPlugin({
filename: 'coliseum.css',
}),
new CopyWebpackPlugin([
{ from: path.join(process.cwd(), 'src/html/app.html') },
{ from: path.join(process.cwd(), 'src/html/index.html') },
{ from: path.join(process.cwd(), 'dependencies/cards.json') },
{ from: path.join(process.cwd(), 'replay.xml') },
]),
// new BundleAnalyzerPlugin(),
],
};
};