Optimize webpack build settings
This commit is contained in:
@@ -191,7 +191,12 @@ module.exports = {
|
|||||||
output: {
|
output: {
|
||||||
publicPath: "/sshwifty/assets/",
|
publicPath: "/sshwifty/assets/",
|
||||||
path: path.join(__dirname, ".tmp", "dist"),
|
path: path.join(__dirname, ".tmp", "dist"),
|
||||||
filename: "[contenthash].js",
|
filename: "[name]-[contenthash:8].js",
|
||||||
|
chunkFormat: "array-push",
|
||||||
|
chunkFilename: "chunk[contenthash:8].js",
|
||||||
|
assetModuleFilename: "asset[contenthash:8][ext]",
|
||||||
|
clean: true,
|
||||||
|
charset: true,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
@@ -201,20 +206,42 @@ module.exports = {
|
|||||||
optimization: {
|
optimization: {
|
||||||
nodeEnv: process.env.NODE_ENV,
|
nodeEnv: process.env.NODE_ENV,
|
||||||
concatenateModules: true,
|
concatenateModules: true,
|
||||||
runtimeChunk: true,
|
runtimeChunk: "single",
|
||||||
mergeDuplicateChunks: true,
|
mergeDuplicateChunks: true,
|
||||||
flagIncludedChunks: true,
|
flagIncludedChunks: true,
|
||||||
providedExports: true,
|
providedExports: true,
|
||||||
usedExports: true,
|
usedExports: true,
|
||||||
|
realContentHash: false,
|
||||||
|
innerGraph: true,
|
||||||
splitChunks: inDevMode
|
splitChunks: inDevMode
|
||||||
? false
|
? false
|
||||||
: {
|
: {
|
||||||
chunks: "all",
|
chunks: "all",
|
||||||
minSize: 102400,
|
minSize: 56000,
|
||||||
maxSize: 244000,
|
maxSize: 110000,
|
||||||
maxAsyncRequests: 6,
|
minRemainingSize: 0,
|
||||||
maxInitialRequests: 6,
|
minChunks: 1,
|
||||||
name: false,
|
maxAsyncRequests: 8,
|
||||||
|
maxInitialRequests: 8,
|
||||||
|
name(module, chunks, cacheGroupKey) {
|
||||||
|
const moduleFileName = module
|
||||||
|
.identifier()
|
||||||
|
.split("/")
|
||||||
|
.reduceRight((item) => item);
|
||||||
|
const allChunksNames = chunks.map((item) => item.name).join("~");
|
||||||
|
return `${cacheGroupKey}~${allChunksNames}~${moduleFileName}`;
|
||||||
|
},
|
||||||
|
cacheGroups: {
|
||||||
|
vendors: {
|
||||||
|
test: /[\\/]node_modules[\\/]/,
|
||||||
|
priority: -10,
|
||||||
|
reuseExistingChunk: true,
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
priority: -20,
|
||||||
|
reuseExistingChunk: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
minimize: !inDevMode,
|
minimize: !inDevMode,
|
||||||
minimizer: inDevMode
|
minimizer: inDevMode
|
||||||
@@ -252,11 +279,7 @@ module.exports = {
|
|||||||
use: "html-loader",
|
use: "html-loader",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
|
test: /\.(ico|jpe?g|png|gif|svg|woff2?)$/i,
|
||||||
use: "file-loader",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(jpe?g|png|gif|svg)$/i,
|
|
||||||
type: "asset",
|
type: "asset",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -268,8 +291,14 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
plugins: (function () {
|
plugins: (function () {
|
||||||
var plugins = [
|
var plugins = [
|
||||||
|
new webpack.optimize.LimitChunkCountPlugin({
|
||||||
|
maxChunks: 7,
|
||||||
|
}),
|
||||||
|
new webpack.optimize.MinChunkSizePlugin({
|
||||||
|
minChunkSize: 56000,
|
||||||
|
}),
|
||||||
new webpack.DefinePlugin(
|
new webpack.DefinePlugin(
|
||||||
process.env.NODE_ENV === "production"
|
!inDevMode
|
||||||
? {
|
? {
|
||||||
"process.env": {
|
"process.env": {
|
||||||
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
|
||||||
@@ -282,6 +311,13 @@ module.exports = {
|
|||||||
handlebarsLoader: {},
|
handlebarsLoader: {},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new webpack.BannerPlugin({
|
||||||
|
banner:
|
||||||
|
"This file is a part of Sshwifty. Automatically " +
|
||||||
|
"generated at " +
|
||||||
|
new Date().toTimeString() +
|
||||||
|
", DO NOT MODIFIY",
|
||||||
|
}),
|
||||||
new ESLintPlugin({}),
|
new ESLintPlugin({}),
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [
|
patterns: [
|
||||||
@@ -334,8 +370,8 @@ module.exports = {
|
|||||||
favicons: {
|
favicons: {
|
||||||
appName: "Sshwifty SSH Client",
|
appName: "Sshwifty SSH Client",
|
||||||
appDescription: "Web SSH Client",
|
appDescription: "Web SSH Client",
|
||||||
developerName: "Rui Ni",
|
developerName: "Ni Rui",
|
||||||
developerURL: "https://vaguly.com",
|
developerURL: "https://nirui.org",
|
||||||
background: "#333",
|
background: "#333",
|
||||||
theme_color: "#333",
|
theme_color: "#333",
|
||||||
appleStatusBarStyle: "black",
|
appleStatusBarStyle: "black",
|
||||||
@@ -394,36 +430,45 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: inDevMode ? "[id].css" : "[contenthash].css",
|
filename: inDevMode ? "[name].css" : "[name]-[contenthash:8].css",
|
||||||
chunkFilename: inDevMode ? "[id].css" : "[contenthash].css",
|
chunkFilename: inDevMode
|
||||||
|
? "[name].css"
|
||||||
|
: "[name]-chunk[contenthash:8].css",
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!inDevMode) {
|
if (!inDevMode) {
|
||||||
plugins.push(
|
plugins.push(
|
||||||
new ImageMinimizerPlugin({
|
new ImageMinimizerPlugin({
|
||||||
severityError: "warning",
|
|
||||||
deleteOriginalAssets: true,
|
|
||||||
maxConcurrency: os.cpus().length,
|
maxConcurrency: os.cpus().length,
|
||||||
minimizerOptions: {
|
minimizerOptions: {
|
||||||
plugins: [
|
plugins: [
|
||||||
|
[
|
||||||
|
"webp",
|
||||||
|
{
|
||||||
|
quality: 50,
|
||||||
|
method: 6,
|
||||||
|
lossless: false,
|
||||||
|
metadata: "none",
|
||||||
|
},
|
||||||
|
],
|
||||||
["gifsicle", { interlaced: true }],
|
["gifsicle", { interlaced: true }],
|
||||||
["mozjpeg", { progressive: true }],
|
["mozjpeg", { progressive: true }],
|
||||||
["pngquant", { quality: [0.0, 0.03] }],
|
["pngquant", { quality: [0.02, 0.2] }],
|
||||||
[
|
//[
|
||||||
"svgo",
|
//"svgo",
|
||||||
{
|
//{
|
||||||
multipass: true,
|
//multipass: true,
|
||||||
datauri: "enc",
|
//datauri: "enc",
|
||||||
indent: 0,
|
//indent: 0,
|
||||||
plugins: [
|
//plugins: [
|
||||||
{
|
//{
|
||||||
sortAttrs: true,
|
//sortAttrs: true,
|
||||||
inlineStyle: true,
|
//inlineStyle: true,
|
||||||
},
|
//},
|
||||||
],
|
//],
|
||||||
},
|
//},
|
||||||
],
|
//],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user