1
0
mirror of https://github.com/WeBankFinTech/fes.js.git synced 2025-04-06 03:59:53 +08:00

fix: 优化 webpack 构建

This commit is contained in:
winixt 2023-03-24 17:35:18 +08:00
parent d9ecc01b86
commit d2fafa9764
7 changed files with 25 additions and 43 deletions
docs/reference/config
packages
fes-builder-webpack
package.json
src/plugins/commands
webpack
webpackConfig
types.d.ts
fes-template-vite
yarn.lock

@ -333,7 +333,7 @@ const defaultTerserOptions = {
- 默认值:`null`
- 详情:
通过 [webpack-chain](https://github.com/neutrinojs/webpack-chain) 的 API 修改 webpack 配置。
通过 [webpack-chain](https://github.com/sorrycc/webpack-chain#readme) 的 API 修改 webpack 配置。
示例:

@ -44,14 +44,14 @@
"connect-history-api-fallback": "^1.6.0",
"copy-webpack-plugin": "^7.0.0",
"css-loader": "^5.0.1",
"fs-extra": "^10.0.0",
"css-minimizer-webpack-plugin": "^4.0.0",
"fs-extra": "^10.0.0",
"get-folder-size": "^2.0.1",
"html-webpack-plugin": "^5.0.0",
"html-webpack-tags-plugin": "^3.0.0",
"get-folder-size": "^2.0.1",
"less": "3.9.0",
"less-loader": "^8.0.0",
"mini-css-extract-plugin": "^1.3.5",
"mini-css-extract-plugin": "^2.7.5",
"postcss": "8.3.0",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-loader": "^4.2.0",
@ -60,8 +60,8 @@
"terser-webpack-plugin": "^5.3.6",
"vue-loader": "^16.1.2",
"webpack": "^5.76.2",
"webpack-5-chain": "^8.0.1",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-chain": "^6.5.1",
"webpack-dev-server": "^4.8.1",
"webpackbar": "^5.0.2"
},
@ -69,4 +69,4 @@
"@fesjs/fes": "3.0.0-rc.8",
"core-js": "^3.27.0"
}
}
}

@ -27,7 +27,7 @@ export default function (api) {
async fn({ options }) {
const assert = require('assert');
const { getBundleAndConfigs } = require('../buildDevUtils');
const { toString } = require('webpack-chain');
const { toString } = require('webpack-5-chain');
const { highlight } = require('cli-highlight');
const { bundleConfig } = await getBundleAndConfigs({ api });

@ -1,6 +1,6 @@
import { join } from 'path';
import { existsSync } from 'fs';
import Config from 'webpack-chain';
import Config from 'webpack-5-chain';
import webpack from 'webpack';
import createCssWebpackConfig from './css';
import getBabelOpts from './getBabelOpts';
@ -78,7 +78,8 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
.path(absoluteOutput)
.publicPath(publicPath || '/')
.filename('js/[name].[contenthash:8].js')
.chunkFilename('js/[name].[contenthash:8].chunk.js');
.chunkFilename('js/[name].[contenthash:8].chunk.js')
.assetModuleFilename('static/[name][hash:8][ext]');
// --------------- resolve -----------
webpackConfig.resolve.extensions.merge(['.mjs', '.js', '.jsx', '.vue', '.ts', '.tsx', '.json', '.wasm']);
@ -293,10 +294,6 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
aggregateTimeout: 200,
...memo.watchOptions,
};
memo.output = {
...memo.output,
assetModuleFilename: 'static/[name][hash:8][ext]',
};
return memo;
}

@ -1,4 +1,4 @@
import Config from 'webpack-chain'
import Config from 'webpack-5-chain'
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin'

@ -2,5 +2,5 @@ import { defineBuildConfig } from '@fesjs/fes';
export default defineBuildConfig({
builder: 'webpack',
publicPath: 'https://gw.alipayobjects.com/',
publicPath: './',
});

@ -8452,14 +8452,12 @@ min-indent@^1.0.0:
resolved "https://registry.npmmirror.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869"
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==
mini-css-extract-plugin@^1.3.5:
version "1.6.2"
resolved "https://registry.npmmirror.com/mini-css-extract-plugin/-/mini-css-extract-plugin-1.6.2.tgz#83172b4fd812f8fc4a09d6f6d16f924f53990ca8"
integrity sha512-WhDvO3SjGm40oV5y26GjMJYjd2UMqrLAGKy5YS2/3QKJy2F7jgynuHTir/tgUUOiNQu5saXHdc8reo7YuhhT4Q==
mini-css-extract-plugin@^2.7.5:
version "2.7.5"
resolved "https://registry.npmmirror.com/mini-css-extract-plugin/-/mini-css-extract-plugin-2.7.5.tgz#afbb344977659ec0f1f6e050c7aea456b121cfc5"
integrity sha512-9HaR++0mlgom81s95vvNjxkg52n2b5s//3ZTI1EtzFb98awsLSivs2LMsVqnQ3ay0PVhqWcGNyDaTE961FOcjQ==
dependencies:
loader-utils "^2.0.0"
schema-utils "^3.0.0"
webpack-sources "^1.1.0"
schema-utils "^4.0.0"
minimalistic-assert@^1.0.0:
version "1.0.1"
@ -10359,11 +10357,6 @@ sockjs@^0.3.24:
uuid "^8.3.2"
websocket-driver "^0.7.4"
source-list-map@^2.0.0:
version "2.0.1"
resolved "https://registry.npmmirror.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==
"source-map-js@>=0.6.2 <2.0.0", source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
@ -11513,6 +11506,14 @@ webidl-conversions@^6.1.0:
resolved "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514"
integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==
webpack-5-chain@^8.0.1:
version "8.0.1"
resolved "https://registry.npmmirror.com/webpack-5-chain/-/webpack-5-chain-8.0.1.tgz#dda9db48c19e4e01e535e84241131bcc777243d8"
integrity sha512-Tu1w80WA2Z+X6e7KzGy+cc0A0z+npVJA/fh55q2azMJ030gqz343Kx+yNAstDCeugsepmtDWY2J2IBRW/O+DEA==
dependencies:
deepmerge "^1.5.2"
javascript-stringify "^2.0.1"
webpack-bundle-analyzer@^4.4.0:
version "4.8.0"
resolved "https://registry.npmmirror.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.8.0.tgz#951b8aaf491f665d2ae325d8b84da229157b1d04"
@ -11529,14 +11530,6 @@ webpack-bundle-analyzer@^4.4.0:
sirv "^1.0.7"
ws "^7.3.1"
webpack-chain@^6.5.1:
version "6.5.1"
resolved "https://registry.npmmirror.com/webpack-chain/-/webpack-chain-6.5.1.tgz#4f27284cbbb637e3c8fbdef43eef588d4d861206"
integrity sha512-7doO/SRtLu8q5WM0s7vPKPWX580qhi0/yBHkOxNkv50f6qB76Zy9o2wRTrrPULqYTvQlVHuvbA8v+G5ayuUDsA==
dependencies:
deepmerge "^1.5.2"
javascript-stringify "^2.0.1"
webpack-dev-middleware@^5.3.1:
version "5.3.3"
resolved "https://registry.npmmirror.com/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz#efae67c2793908e7311f1d9b06f2a08dcc97e51f"
@ -11583,14 +11576,6 @@ webpack-dev-server@^4.8.1:
webpack-dev-middleware "^5.3.1"
ws "^8.4.2"
webpack-sources@^1.1.0:
version "1.4.3"
resolved "https://registry.npmmirror.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
integrity sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==
dependencies:
source-list-map "^2.0.0"
source-map "~0.6.1"
webpack-sources@^3.2.3:
version "3.2.3"
resolved "https://registry.npmmirror.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"