Skip to content

Commit 9ac03a4

Browse files
committed
feat(scripts): compile node-modules with babel-loader
Add support for compiling node_modules with our own babel preset. See #471
1 parent b39950c commit 9ac03a4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/scripts/src/config/WebpackConfigHelper.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,34 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
465465
],
466466
exclude: /(node_modules)/,
467467
};
468+
469+
// Compile node_modules
470+
const nmJsRules: webpack.RuleSetRule = {
471+
test: /\.(js|mjs)$/,
472+
// we exclude @babel/runtime and core-js
473+
exclude: /(@babel(?:\/|\\{1,2})runtime)|(core-js)/,
474+
include: /node_modules/,
475+
use: [
476+
{
477+
loader: 'babel-loader',
478+
options: {
479+
// cache
480+
...babelLoaderCacheOptions,
481+
// preset from our own package
482+
presets: getBabelPresets({ hasReact: false }),
483+
// If an error happens in a package, it's possible to be
484+
// because it was compiled. Thus, we don't want the browser
485+
// debugger to show the original code. Instead, the code
486+
// being evaluated would be much more helpful.
487+
sourceMaps: false,
488+
// disable babelrc and babel.config.js for node_modules
489+
configFile: false,
490+
babelrc: false,
491+
},
492+
},
493+
],
494+
};
495+
468496
// Create style rules
469497
const styleRules: webpack.RuleSetRule = {
470498
test: /\.css$/,
@@ -516,6 +544,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
516544
rules: [
517545
jsRules,
518546
tsRules,
547+
nmJsRules,
519548
styleRules,
520549
fileRulesNonStyle,
521550
fileRulesStyle,

0 commit comments

Comments
 (0)