1 | const GenerateJsonPlugin = require('generate-json-webpack-plugin')
|
2 | const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
3 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
4 |
|
5 | const selection = require('./src/selection.json')
|
6 |
|
7 | const iconsJson = selection.icons.map((icon) => icon.properties.name).sort()
|
8 |
|
9 | const pathsJson = selection.icons.reduce((acc, { properties, icon }) => {
|
10 | return {
|
11 | ...acc,
|
12 | [properties.name]: icon.paths.join(' '),
|
13 | }
|
14 | }, {})
|
15 |
|
16 | const config = {
|
17 | mode: 'production',
|
18 | entry: './src/main.scss',
|
19 | module: {
|
20 | rules: [
|
21 | {
|
22 | test: /\.(eot|svg|ttf|woff2?)$/,
|
23 | loader: 'file-loader',
|
24 | options: {
|
25 | esModule: false,
|
26 | },
|
27 | },
|
28 | {
|
29 | test: /\.s?css$/,
|
30 | use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
|
31 | },
|
32 | ],
|
33 | },
|
34 | plugins: [
|
35 | new GenerateJsonPlugin('icons.json', iconsJson),
|
36 | new GenerateJsonPlugin('paths.json', pathsJson),
|
37 | new MiniCssExtractPlugin({
|
38 | filename: 'icons.css',
|
39 | }),
|
40 | ],
|
41 | }
|
42 |
|
43 | if (process.env.NODE_ENV === 'production') {
|
44 | config.plugins.push(new OptimizeCSSAssetsPlugin())
|
45 | }
|
46 |
|
47 | module.exports = config
|