Skip to content

Commit ce5906d

Browse files
authored
Add webpack sdk resolveAliases registry as well as transpiledDependencies registry. (#132)
1 parent 75cbfd6 commit ce5906d

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

.core/webpack.sdk.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class WebpackReactiumWebpack {
5151
minimize: false,
5252
};
5353

54+
this.resolveAliases = ReactiumWebpack.Utils.registryFactory(
55+
'resolveAliases',
56+
'id',
57+
ReactiumWebpack.Utils.Registry.MODES.CLEAN,
58+
);
59+
this.resolveAliases.sdk = this;
60+
61+
this.transpiledDependencies = ReactiumWebpack.Utils.registryFactory(
62+
'transpiledDependencies',
63+
'module',
64+
ReactiumWebpack.Utils.Registry.MODES.CLEAN,
65+
);
66+
this.transpiledDependencies.sdk = this;
67+
5468
this.ignores = ReactiumWebpack.Utils.registryFactory(
5569
'ignores',
5670
'id',
@@ -159,6 +173,10 @@ class WebpackReactiumWebpack {
159173
return this.overridesValue || {};
160174
}
161175

176+
addResolveAlias(id, alias) {
177+
this.resolveAliases.register(id, { alias });
178+
}
179+
162180
addRule(id, rule) {
163181
this.rules.register(id, { rule });
164182
}
@@ -171,6 +189,10 @@ class WebpackReactiumWebpack {
171189
this.plugins.register(id, { plugin });
172190
}
173191

192+
addTranspiledDependency(module) {
193+
this.transpiledDependencies.register(module);
194+
}
195+
174196
addContext(id, context) {
175197
const { from, to } = context;
176198
this.plugins.register(id, {
@@ -365,7 +387,29 @@ class WebpackReactiumWebpack {
365387
config() {
366388
ReactiumWebpack.Hook.runSync('before-config', this);
367389

368-
return {
390+
if (this.transpiledDependencies.list.length > 0) {
391+
this.addRule('babel-loader', {
392+
test: [/\.jsx|js($|\?)/],
393+
exclude: [
394+
new RegExp(
395+
`node_modules\/(?!(${this.transpiledDependencies.list
396+
.map(({ module }) => module)
397+
.join('|')})\/).*`,
398+
),
399+
/umd.js$/,
400+
],
401+
resolve: {
402+
extensions: ['.js', '.jsx', '.json'],
403+
},
404+
use: [
405+
{
406+
loader: 'babel-loader',
407+
},
408+
],
409+
});
410+
}
411+
412+
const theConfig = {
369413
mode: this.mode,
370414
target: this.target,
371415
output: this.output,
@@ -381,6 +425,17 @@ class WebpackReactiumWebpack {
381425
plugins: this.getPlugins(),
382426
...this.overrides,
383427
};
428+
429+
if (this.resolveAliases.list.length > 0) {
430+
const alias = {};
431+
this.resolveAliases.list.forEach(({ id: from, alias: to }) => {
432+
alias[from] = to;
433+
});
434+
theConfig.resolve = { alias };
435+
}
436+
437+
ReactiumWebpack.Hook.runSync('after-config', theConfig, this);
438+
return theConfig;
384439
}
385440
}
386441

0 commit comments

Comments
 (0)