-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugins.js
158 lines (146 loc) · 4.27 KB
/
plugins.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const { IgnorePlugin } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
var FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const HtmlIncAssetsPlugin = require('html-webpack-include-assets-plugin');
const safePostCssParser = require('postcss-safe-parser');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const CopyPlugin = require('copy-webpack-plugin');
const paths = require('../paths');
const staticFiles = require('./static-files');
const minifyHtml = {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
};
const getPlugins = (isEnvProduction = false, shouldUseSourceMap = false) => {
/* HTML Plugins for options, sidebar, options */
const optionsHtmlPlugin = new HtmlWebpackPlugin(
Object.assign(
{},
{
title: 'Options',
chunks: ['options'],
filename: 'options.html',
template: paths.optionsTemplate,
},
isEnvProduction
? {
minify: minifyHtml,
}
: undefined
)
);
const popupHtmlPlugin = new HtmlWebpackPlugin(
Object.assign(
{},
{
title: 'Popup',
chunks: ['popup'],
filename: 'popup.html',
template: paths.popupTemplate,
},
isEnvProduction
? {
minify: minifyHtml,
}
: undefined
)
);
const sidebarHtmlPlugin = new HtmlWebpackPlugin(
Object.assign(
{},
{
title: 'Sidebar',
chunks: ['sidebar'],
filename: 'sidebar.html',
template: paths.sidebarTemplate,
},
isEnvProduction
? {
minify: minifyHtml,
}
: undefined
)
);
const moduleNotFoundPlugin = new ModuleNotFoundPlugin(paths.appPath);
const caseSensitivePathsPlugin = new CaseSensitivePathsPlugin();
const watchMissingNodeModulesPlugin = new WatchMissingNodeModulesPlugin(paths.appNodeModules);
const miniCssExtractPlugin = new MiniCssExtractPlugin({
filename: '[name].css',
// chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
});
const ignorePlugin = new IgnorePlugin(/^\.\/locale$/, /moment$/);
const terserPlugin = new TerserPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: true,
cache: true,
sourceMap: shouldUseSourceMap,
});
const optimizeCSSAssetsPlugin = new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
parser: safePostCssParser,
map: shouldUseSourceMap
? {
inline: false,
annotation: true,
}
: false,
},
});
/* Include these static JS and CSS assets in the generated HTML files */
const htmlIncAssetsPlugin = new HtmlIncAssetsPlugin({
append: false,
assets: staticFiles.htmlAssets,
});
const moduleScopePlugin = new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]);
const copyPlugin = new CopyPlugin(staticFiles.copyPatterns);
const friendlyErrorsWebpackPlugin = new FriendlyErrorsWebpackPlugin();
return {
optionsHtmlPlugin,
popupHtmlPlugin,
sidebarHtmlPlugin,
moduleNotFoundPlugin,
caseSensitivePathsPlugin,
watchMissingNodeModulesPlugin,
miniCssExtractPlugin,
ignorePlugin,
terserPlugin,
optimizeCSSAssetsPlugin,
moduleScopePlugin,
copyPlugin,
htmlIncAssetsPlugin,
friendlyErrorsWebpackPlugin
};
};
module.exports = getPlugins;