mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
fix: 修复hardSoureWebpackPlugin在webpack的define插件变化时依然使用cache的bug
默认使用node-object-hash对webpackConfig处理计算hash,插件配置解析为[Object, object],所以define插件配置发生变化,产生的hash一样
This commit is contained in:
parent
0c74a62fa0
commit
4c1831cf64
@ -1,8 +1,3 @@
|
|||||||
import {
|
|
||||||
winPath
|
|
||||||
} from '@umijs/utils';
|
|
||||||
import HardSourceWebpackPlugin from 'hard-source-webpack-plugin';
|
|
||||||
|
|
||||||
export default (api) => {
|
export default (api) => {
|
||||||
api.describe({
|
api.describe({
|
||||||
key: 'hardSource',
|
key: 'hardSource',
|
||||||
@ -14,12 +9,31 @@ export default (api) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
api.chainWebpack((webpackConfig) => {
|
api.chainWebpack((webpackConfig) => {
|
||||||
|
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
|
||||||
|
const { winPath } = require('@umijs/utils');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const path = require('path');
|
||||||
|
const { toString } = require('webpack-chain');
|
||||||
const cwd = api.cwd;
|
const cwd = api.cwd;
|
||||||
if (api.env === 'development') {
|
if (api.env === 'development') {
|
||||||
webpackConfig
|
webpackConfig
|
||||||
.plugin('hardSource')
|
.plugin('hardSource')
|
||||||
.use(HardSourceWebpackPlugin, [{
|
.use(HardSourceWebpackPlugin, [{
|
||||||
cacheDirectory: winPath(`${cwd}/.cache/hard-source/[confighash]`),
|
cacheDirectory: winPath(`${cwd}/.cache/hard-source/[confighash]`),
|
||||||
|
configHash: (config) => {
|
||||||
|
const hardSourcePlugin = config.plugins.find(
|
||||||
|
({ constructor }) => constructor.name === 'HardSourceWebpackPlugin'
|
||||||
|
);
|
||||||
|
const cacheDir = hardSourcePlugin.getCachePath();
|
||||||
|
const context = path.resolve(process.cwd(), config.context);
|
||||||
|
const clone = Object.assign({}, config, {
|
||||||
|
context: path.relative(cacheDir, context)
|
||||||
|
});
|
||||||
|
return crypto
|
||||||
|
.createHash('sha256')
|
||||||
|
.update(toString(clone))
|
||||||
|
.digest('hex');
|
||||||
|
},
|
||||||
...api.config.hardSource || {}
|
...api.config.hardSource || {}
|
||||||
}]);
|
}]);
|
||||||
webpackConfig
|
webpackConfig
|
||||||
|
Loading…
x
Reference in New Issue
Block a user