1 | 'use strict'
|
2 |
|
3 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
4 | const CopyWebpackPlugin = require('copy-webpack-plugin')
|
5 | const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin')
|
6 | const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
|
7 | const HtmlWebpackPlugin = require('html-webpack-plugin')
|
8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
9 | const ProgressBarPlugin = require('progress-bar-webpack-plugin')
|
10 | const SVGSymbolSprite = require('svg-symbol-sprite-loader')
|
11 | const chalk = require('chalk')
|
12 | const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
13 | const {
|
14 | EnvironmentPlugin,
|
15 | HotModuleReplacementPlugin,
|
16 | NamedModulesPlugin,
|
17 | } = require('webpack')
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | module.exports = ({ chunkHash, devServer, envVars, flags, publicPath, paths }) => ({
|
26 |
|
27 |
|
28 |
|
29 | caseSensitivePathsPlugin: new CaseSensitivePathsPlugin(),
|
30 |
|
31 |
|
32 |
|
33 | cleanPlugin: new CleanWebpackPlugin(),
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | copyPlugin: new CopyWebpackPlugin([paths.static]),
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | duplicatePackageCheckerPlugin: new DuplicatePackageCheckerPlugin({
|
44 | verbose: true,
|
45 | }),
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | environmentPlugin: new EnvironmentPlugin({
|
51 | DEBUG: false,
|
52 | PUBLIC_PATH: publicPath,
|
53 | ...envVars,
|
54 | }),
|
55 |
|
56 |
|
57 |
|
58 | friendlyErrorsPlugin: new FriendlyErrorsWebpackPlugin({
|
59 | compilationSuccessInfo: {
|
60 | messages: [
|
61 | ` đ ${chalk.green.bold('BINGO')} đ`,
|
62 | ` Application running at ${chalk.blue.underline(
|
63 | `http://${devServer.host || 'localhost'}:${devServer.port || 3000}`,
|
64 | )}`,
|
65 | ],
|
66 | notes: [
|
67 | `webpack output is served from ${publicPath}`,
|
68 | `Content not from webpack is served from ${paths.static}`,
|
69 | `404s will fallback to /index.html`,
|
70 | ],
|
71 | },
|
72 | }),
|
73 |
|
74 |
|
75 |
|
76 | hotModuleReplacementPlugin: new HotModuleReplacementPlugin(),
|
77 |
|
78 |
|
79 |
|
80 | htmlPlugin: new HtmlWebpackPlugin({
|
81 | favicon: `${paths.static}/favicon.ico`,
|
82 | inject: !flags.electron,
|
83 | minify: false,
|
84 | template: paths.htmlTemplate,
|
85 | }),
|
86 |
|
87 |
|
88 | miniCSSExtractPlugin: new MiniCssExtractPlugin({
|
89 | filename: `static/css/[name]${chunkHash}.css`,
|
90 | }),
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | namedModulesPlugin: new NamedModulesPlugin(),
|
100 |
|
101 |
|
102 |
|
103 | progressBarPlugin: new ProgressBarPlugin({
|
104 |
|
105 | callback: () => console.log(`\n đ ${chalk.bold('BINGO')} đ\n`),
|
106 |
|
107 | clear: false,
|
108 | format: ` Hacking time... [:bar] ${chalk.green.bold(
|
109 | ':percent',
|
110 | )} (:elapsed seconds) :msg`,
|
111 | }),
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | svgSymbolSpritePlugin: new SVGSymbolSprite.Plugin({
|
118 | filename: `static/media/icon-sprite${chunkHash}.svg`,
|
119 |
|
120 |
|
121 |
|
122 | injectSpriteId: !(flags.electron || flags.storybook),
|
123 | }),
|
124 | })
|