-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
73 lines (68 loc) · 1.86 KB
/
webpack.common.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
'use strict';
let path = require('path');
let CopyWebpackPlugin = require('copy-webpack-plugin');
let CleanWebpackPlugin = require('clean-webpack-plugin');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let HtmlWebpackExcludeEmptyAssetsPlugin = require('html-webpack-exclude-empty-assets-plugin');
let _ = require('lodash');
let webpack = require('webpack');
let config = require('./config');
let defaults = {
libraries: ['portal'],
chunks: {
portal: ['./src/index.js']
}
};
module.exports = {
entry: defaults.chunks,
output: {
filename: '[name].js',
path: config.build.dist
},
resolve: {
extensions: ['.js', '.ts']
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader'
]
},
{
test: /default\.mustache$/,
loader: 'mustache-loader',
options: {
tiny: true,
render: config.site.head,
},
}
]
},
plugins: [
new CleanWebpackPlugin(['dist']),
new CopyWebpackPlugin(config.copy.faulker, { debug: 'warning' })
].concat(_.map(config.site.pages, page => new HtmlWebpackPlugin(_.merge({
hash: false,
inject: !_.isNil(page.scope) ? page.scope : 'body',
filename: page.name, //relative to root of the application
chunks: !_.isNil(page.lib) ? _.isArrayLikeObject(page.lib) ? page.lib.concat(defaults.libraries)
: [page.lib].concat(defaults.libraries) : defaults.libraries,
minify: config.minify //trim the rendered html source ...
}, !_.isNil(page.file) ? { template: page.file } : {} ))
)).concat(new HtmlWebpackExcludeEmptyAssetsPlugin())
};