This repository has been archived by the owner on May 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
149 lines (139 loc) · 3.53 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
138
139
140
141
142
143
144
145
146
147
148
149
const webpack = require('webpack');
const merge = require('webpack-merge');
const path = require('path');
const glob = require('glob');
const minimatch = require('minimatch');
const dotenv = require('dotenv').config({ path: __dirname + '/.env' });
// various webpack goodies
const parts = require('./webpack.parts');
// application-specific PATHS
const paths = require('./paths');
const DEVELOPMENT = 'development';
const PRODUCTION = 'production';
const HOST = process.env.HOST;
const PORT = process.env.PORT;
const ASSET_PATH = process.env.ASSET_PATH || '/dist';
const envFile = {};
envFile['BASE_PATH'] = JSON.stringify('');
// Populate the env dict with Environment variables from the system
if (process.env) {
Object.keys(process.env).map(key => {
envFile[key] = JSON.stringify(process.env[key]);
});
}
// Update the env dict with any in the .env file
if (dotenv.parsed) {
Object.keys(dotenv.parsed).map(key => {
envFile[key] = JSON.stringify(dotenv.parsed[key]);
});
}
const BUILD_FILE_NAMES = {
css: '[name].[contentHash].css',
bundle: '[name].[contentHash].bundle.js',
assets: 'assets/[name].[hash:4].[ext]',
};
const commonConfig = merge([
{
entry: {
main: [
'./vendor.ts',
'./modules/core/client/app/ApplicationConfiguration.ts'
].concat(
glob.sync('./modules/*/client/*.{js,ts}'),
glob.sync('./modules/*/client/**/*.{js,ts}', {
ignore: [
'./modules/*/client/*.{js,ts}',
'./main.js',
'./modules/core/client/app/ApplicationConfiguration.ts'
]
}),
glob.sync('./modules/*/client/**/*.html'),
),
},
resolve: {
// These files are tried when trying to resolve a directory...
// - i.e. require("/some/dir") -> require("some/dir/index.js")
mainFiles: ['index', 'compile/minified/ng-img-crop']
},
},
parts.loadServerViews(),
parts.setEnvironmentVariables(envFile),
parts.loadFonts({
urlLoaderOptions: {
// Inline files smaller than 10 kB (10240 bytes)
limit: 10 * 1024,
name: 'fonts/[name].[ext]',
publicPath: ASSET_PATH,
fallback: 'file-loader',
}
}),
parts.loadTS({
exclude: /node_modules/,
}),
parts.provideJQuery(),
]);
const devConfig = merge([
{
output: {
path: paths.build,
publicPath: ASSET_PATH,
filename: BUILD_FILE_NAMES.bundle,
},
watch: process.env.LIVERELOAD || false,
},
parts.clean(paths.build),
parts.loadLiveReload(),
parts.loadHashedModuleIds(),
parts.generateSourceMaps({
type: "source-map",
}),
parts.splitVendorChunks({
filename: BUILD_FILE_NAMES.vendor,
}),
parts.loadHtml(),
parts.extractCSS({
filename: BUILD_FILE_NAMES.css,
}),
parts.loadTinyMCE(),
parts.loadImages({
urlLoaderOptions: {
// Inline files smaller than 10 kB (10240 bytes)
limit: 10 * 1024,
name: 'images/[name].[ext]',
publicPath: ASSET_PATH,
fallback: 'file-loader',
},
}),
]);
const prodConfig = merge([
{
output: {
path: paths.build,
publicPath: ASSET_PATH,
filename: BUILD_FILE_NAMES.bundle,
},
},
parts.clean(paths.build),
parts.loadHashedModuleIds(),
parts.splitVendorChunks(),
parts.loadHtml(),
parts.extractCSS({
filename: BUILD_FILE_NAMES.css,
}),
parts.loadTinyMCE(),
parts.loadImages({
urlLoaderOptions: {
// Inline files smaller than 10 kB (10240 bytes)
limit: 10 * 1024,
name: 'fonts/[name].[ext]',
publicPath: ASSET_PATH,
fallback: 'file-loader',
},
}),
parts.minifyJS(),
]);
module.exports = (mode) => {
// return env-specific configuration - i.e. dev vs prod
const config = mode === PRODUCTION ? prodConfig : devConfig;
return merge(commonConfig, config, { mode });
};