This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
/
webpack.config.js
137 lines (125 loc) · 3.58 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
129
130
131
132
133
134
135
136
137
const path = require('path');
const webpack = require('webpack');
const DefinePlugin = webpack.DefinePlugin;
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin').CleanWebpackPlugin;
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
const pkg = require('./package.json');
// Environment config
const NODE_ENV = process.env.NODE_ENV || 'production';
const DIST_DIR = path.join(__dirname, 'build');
const isProduction = NODE_ENV === 'production';
const BuildConfig = require('./build.config');
const env = BuildConfig.entries();
const manifestFiles = BuildConfig.manifestFiles();
console.log(`
Building Augury with the following environment options:
${Object.keys(env)
.map(k => `${k}: ${env[k]}`)
.join('\n ')}
`);
/*
* Config
*/
module.exports = {
mode: env.PROD_MODE ? 'production' : 'development',
devtool: env.PROD_MODE ? false : ' source-map',
cache: true,
context: __dirname,
stats: {
colors: true,
reasons: true
},
entry: {
frontend: ['./src/frontend/vendor', './src/frontend/main'],
backend: ['./src/backend/backend'],
'ng-validate': ['./src/utils/ng-validate'],
devtools: ['./src/devtools/devtools'],
'content-script': ['./src/content-script'],
background: [
'./src/channel/channel',
'./src/sentry-connection/sentry-connection',
'./src/gtm-connection/gtm-connection'
]
},
// Config for our build files
output: {
path: DIST_DIR,
filename: '[name].js',
sourceMapFilename: '[name].js.map',
chunkFilename: '[name].chunk.js'
},
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: ['./node_modules'],
alias: {
backend: path.resolve('./src/backend'),
frontend: path.resolve('./src/frontend'),
communication: path.resolve('./src/communication'),
'feature-modules': path.resolve('./src/feature-modules'),
tree: path.resolve('./src/tree')
}
},
// Opt-in to the old behavior with the resolveLoader.moduleExtensions
// - https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed
resolveLoader: {
modules: ['./node_modules'],
moduleExtensions: ['-loader']
},
module: {
rules: [
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
use: '@ngtools/webpack'
},
{
test: /\.css$/,
use: ['to-string-loader', 'css-loader', 'postcss-loader']
},
{
test: /\.png$/,
use: 'url-loader?mimetype=image/png'
},
{
test: /\.html$/,
use: 'raw-loader'
}
]
},
plugins: [
new ProgressPlugin(),
new CleanWebpackPlugin(),
new DefinePlugin(BuildConfig.stringifyValues(env)),
new AngularCompilerPlugin({
tsConfigPath: 'tsconfig.json',
mainPath: './src/frontend/main',
entryModule: './src/frontend/module#FrontendModule',
sourceMap: true
}),
new MergeJsonWebpackPlugin({
files: manifestFiles,
output: {
fileName: '../manifest.json'
}
})
].concat(
env.PROD_MODE
? [
// ... prod-only pluginss
]
: [
// ... dev-only plugins
// new BundleAnalyzerPlugin(),
]
),
/*
* When using `templateUrl` and `styleUrls` please use `__filename`
* rather than `module.id` for `moduleId` in `@View`
*/
node: {
crypto: false,
__filename: true
}
};