Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion .core/webpack.sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class WebpackReactiumWebpack {
minimize: false,
};

this.resolveAliases = ReactiumWebpack.Utils.registryFactory(
'resolveAliases',
'id',
ReactiumWebpack.Utils.Registry.MODES.CLEAN,
);
this.resolveAliases.sdk = this;

this.transpiledDependencies = ReactiumWebpack.Utils.registryFactory(
'transpiledDependencies',
'module',
ReactiumWebpack.Utils.Registry.MODES.CLEAN,
);
this.transpiledDependencies.sdk = this;

this.ignores = ReactiumWebpack.Utils.registryFactory(
'ignores',
'id',
Expand Down Expand Up @@ -159,6 +173,10 @@ class WebpackReactiumWebpack {
return this.overridesValue || {};
}

addResolveAlias(id, alias) {
this.resolveAliases.register(id, { alias });
}

addRule(id, rule) {
this.rules.register(id, { rule });
}
Expand All @@ -171,6 +189,10 @@ class WebpackReactiumWebpack {
this.plugins.register(id, { plugin });
}

addTranspiledDependency(module) {
this.transpiledDependencies.register(module);
}

addContext(id, context) {
const { from, to } = context;
this.plugins.register(id, {
Expand Down Expand Up @@ -365,7 +387,29 @@ class WebpackReactiumWebpack {
config() {
ReactiumWebpack.Hook.runSync('before-config', this);

return {
if (this.transpiledDependencies.list.length > 0) {
this.addRule('babel-loader', {
test: [/\.jsx|js($|\?)/],
exclude: [
new RegExp(
`node_modules\/(?!(${this.transpiledDependencies.list
.map(({ module }) => module)
.join('|')})\/).*`,
),
/umd.js$/,
],
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
use: [
{
loader: 'babel-loader',
},
],
});
}

const theConfig = {
mode: this.mode,
target: this.target,
output: this.output,
Expand All @@ -381,6 +425,17 @@ class WebpackReactiumWebpack {
plugins: this.getPlugins(),
...this.overrides,
};

if (this.resolveAliases.list.length > 0) {
const alias = {};
this.resolveAliases.list.forEach(({ id: from, alias: to }) => {
alias[from] = to;
});
theConfig.resolve = { alias };
}

ReactiumWebpack.Hook.runSync('after-config', theConfig, this);
return theConfig;
}
}

Expand Down