-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.hub.js
103 lines (99 loc) · 2.99 KB
/
webpack.config.hub.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
const Webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const path = require('path');
const fs = require('fs');
module.exports = function(ctx) {
// Get policies
let policiesHtmlPlugins = [];
let policiesPath = path.resolve(ctx.commonPath, 'static/policies');
let pages = [ 'login', 'verify', 'reset', 'account', 'styleguide' ];
fs.readdirSync(policiesPath).forEach(file => {
let policy = JSON.parse(fs.readFileSync(path.resolve(policiesPath, file), 'utf8'));
policiesHtmlPlugins.push(new HtmlWebpackPlugin({
filename: 'policy/' + policy.slug + '.html',
template: path.resolve(ctx.srcPath, ctx.devMode
? 'policy/' + policy.slug + '.ejs'
: 'policy/index.ejs',
),
templateParameters: {
title: ctx.siteConfig.APP_TITLE,
policyTitle: policy.title,
policyCreated: policy.created,
policyBody: policy.body,
},
chunks: [ 'policy' ],
}));
});
return {
entry: {
app: path.resolve(ctx.srcPath, 'app.js'),
policy: path.resolve(ctx.srcPath, 'policy/app-policy.js'),
...pages.reduce((o, page) => Object.assign(o, { [page]: path.resolve(ctx.srcPath, page + '/app-' + page + '.js') }), {}),
},
performance: {
hints: ctx.devMode ? false : 'warning',
maxEntrypointSize: 512000,
maxAssetSize: 2048000,
},
devServer: {
port: 6460,
allowedHosts: [
'localhost',
'mucklet.localhost',
],
proxy: {
'/identity': {
target: 'http://127.0.0.1:6451',
pathRewrite: { '^/identity': '' },
// logLevel: 'debug'
},
'/api': {
target: 'http://127.0.0.1:8080',
// logLevel: 'debug'
},
},
},
plugins: [
new CleanWebpackPlugin(),
new ESLintPlugin({
exclude: [
'node_modules/',
],
emitWarning: true,
}),
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(ctx.commonPath, 'static') },
{ from: path.resolve(ctx.srcPath, 'static') },
],
}),
new HtmlWebpackPlugin({
template: path.resolve(ctx.srcPath, 'index.html'),
title: ctx.siteConfig.APP_TITLE,
chunks: [ 'app' ],
}),
...pages.map(page => new HtmlWebpackPlugin({
filename: page + '/index.html',
template: path.resolve(ctx.srcPath, page + '/index.html'),
title: ctx.siteConfig.APP_TITLE,
chunks: [ page ],
})),
...policiesHtmlPlugins,
new MiniCssExtractPlugin({
filename: ctx.devMode ? '[name].css' : '[name].[contenthash:8].css',
chunkFilename: ctx.devMode ? '[name].css' : '[name].[contenthash:8].css',
}),
new Webpack.DefinePlugin(Object.assign(ctx.jsonEncodeObject(ctx.siteConfig), {
APP_VERSION: JSON.stringify(ctx.pkg.version),
})),
new GenerateJsonPlugin('info.json', {
version: ctx.pkg.version,
}),
],
};
};