-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
64 lines (61 loc) · 2.09 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
const bundleName = 'ui-bundle'
const path = require('path')
const ZipPlugin = require('zip-webpack-plugin');
const FaviconsPlugin = require('favicons-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const HtmlPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const get = require('lodash/get')
const htmlHeadTags = ({ fileName, filterKey, filterValue }) => {
const getTemplateContent = (htmlWebpackPlugin) => htmlWebpackPlugin.tags.headTags
.filter(tagNode => get(tagNode, filterKey) === filterValue)
.join('')
// It must be Handlebars template with root path as variable
.replaceAll('uiRootPath', '{{{uiRootPath}}}')
return new HtmlPlugin({
publicPath: 'uiRootPath',
templateContent: ({htmlWebpackPlugin}) => `${getTemplateContent(htmlWebpackPlugin)}`,
filename: `partials/${fileName}`,
inject: false
})
}
module.exports = {
mode: 'production',
module: {
rules: [
{
test: /\.(sc|sa|c)ss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: './css/[name].[contenthash].css'
}),
new ZipPlugin({ filename: bundleName }),
htmlHeadTags({fileName: 'head-icons.hbs', filterKey: 'meta.plugin', filterValue: 'favicons-webpack-plugin'}),
htmlHeadTags({fileName: 'head-styles.hbs', filterKey: 'attributes.rel', filterValue: 'stylesheet'}),
htmlHeadTags({fileName: 'head-local-scripts.hbs', filterKey: 'tagName', filterValue: 'script'}),
new FaviconsPlugin({
logo: 'logo.svg',
favicons: { appName: 'Taymyr' },
prefix: 'assets/[contenthash]/',
inject: htmlPlugin => path.basename(htmlPlugin.options.filename).endsWith('head-icons.hbs')
}),
new CopyPlugin({
patterns: [
{ from: 'src/layouts', to: 'layouts' },
{ from: 'src/partials', to: 'partials' },
]
}),
],
performance: {
assetFilter: (filename) => !filename.startsWith(bundleName)
}
};