diff --git a/packages/fes-preset-built-in/src/plugins/features/hardSource.js b/packages/fes-preset-built-in/src/plugins/features/hardSource.js index 7622f399..59e1d132 100644 --- a/packages/fes-preset-built-in/src/plugins/features/hardSource.js +++ b/packages/fes-preset-built-in/src/plugins/features/hardSource.js @@ -1,8 +1,3 @@ -import { - winPath -} from '@umijs/utils'; -import HardSourceWebpackPlugin from 'hard-source-webpack-plugin'; - export default (api) => { api.describe({ key: 'hardSource', @@ -14,12 +9,31 @@ export default (api) => { }); 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; if (api.env === 'development') { webpackConfig .plugin('hardSource') .use(HardSourceWebpackPlugin, [{ 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 || {} }]); webpackConfig