Skip to content

Commit 4a34944

Browse files
committed
fix wasm webpack dynamic require handling
1 parent 5ef8e5d commit 4a34944

2 files changed

Lines changed: 32 additions & 40 deletions

File tree

mpp-core/webpack.config.d/node-polyfills.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,25 @@ config.module = config.module || {};
2828
config.module.unknownContextCritical = false;
2929
config.module.exprContextCritical = false;
3030

31-
// Add webpack plugin to ignore wasm-git's dynamic requires
32-
const webpack = require('webpack');
33-
config.plugins.push(
34-
new webpack.ContextReplacementPlugin(
35-
/wasm-git/,
36-
(data) => {
37-
// Ignore all dynamic requires in wasm-git
38-
delete data.dependencies[0].critical;
39-
return data;
40-
}
41-
)
42-
);
31+
config.plugins = config.plugins || [];
4332

44-
// Ignore specific problematic requires in wasm-git
45-
config.plugins.push(
46-
new webpack.IgnorePlugin({
47-
resourceRegExp: /^\.\/$/,
48-
contextRegExp: /wasm-git/
49-
})
50-
);
33+
config.plugins.push({
34+
apply(compiler) {
35+
const normalModuleFactory = compiler && compiler.hooks && compiler.hooks.normalModuleFactory;
36+
if (!normalModuleFactory) return;
37+
38+
normalModuleFactory.tap('AutoDevIgnoreWasmGitDynamicRequire', (factory) => {
39+
factory.hooks.beforeResolve.tap('AutoDevIgnoreWasmGitDynamicRequire', (request) => {
40+
if (request && /wasm-git/.test(request.context || '') && request.request === './') {
41+
return false;
42+
}
43+
return undefined;
44+
});
45+
});
46+
}
47+
});
5148

5249
// Copy tree-sitter.wasm and language WASM files to the output directory
53-
config.plugins = config.plugins || [];
5450
config.plugins.push(
5551
new CopyWebpackPlugin({
5652
patterns: [

mpp-ui/webpack.config.d/node-polyfills.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,25 @@ config.module = config.module || {};
2828
config.module.unknownContextCritical = false;
2929
config.module.exprContextCritical = false;
3030

31-
// Add webpack plugin to ignore wasm-git's dynamic requires
32-
const webpack = require('webpack');
33-
config.plugins.push(
34-
new webpack.ContextReplacementPlugin(
35-
/wasm-git/,
36-
(data) => {
37-
// Ignore all dynamic requires in wasm-git
38-
delete data.dependencies[0].critical;
39-
return data;
40-
}
41-
)
42-
);
31+
config.plugins = config.plugins || [];
4332

44-
// Ignore specific problematic requires in wasm-git
45-
config.plugins.push(
46-
new webpack.IgnorePlugin({
47-
resourceRegExp: /^\.\/$/,
48-
contextRegExp: /wasm-git/
49-
})
50-
);
33+
config.plugins.push({
34+
apply(compiler) {
35+
const normalModuleFactory = compiler && compiler.hooks && compiler.hooks.normalModuleFactory;
36+
if (!normalModuleFactory) return;
37+
38+
normalModuleFactory.tap('AutoDevIgnoreWasmGitDynamicRequire', (factory) => {
39+
factory.hooks.beforeResolve.tap('AutoDevIgnoreWasmGitDynamicRequire', (request) => {
40+
if (request && /wasm-git/.test(request.context || '') && request.request === './') {
41+
return false;
42+
}
43+
return undefined;
44+
});
45+
});
46+
}
47+
});
5148

5249
// Copy tree-sitter.wasm and language WASM files to the output directory
53-
config.plugins = config.plugins || [];
5450
config.plugins.push(
5551
new CopyWebpackPlugin({
5652
patterns: [

0 commit comments

Comments
 (0)