Skip to content

Commit

Permalink
feat(scripts): compile node-modules with babel-loader
Browse files Browse the repository at this point in the history
Add support for compiling node_modules with our own babel preset.

See #471
  • Loading branch information
swashata committed Apr 28, 2019
1 parent b39950c commit 9ac03a4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/scripts/src/config/WebpackConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,34 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
],
exclude: /(node_modules)/,
};

// Compile node_modules
const nmJsRules: webpack.RuleSetRule = {
test: /\.(js|mjs)$/,
// we exclude @babel/runtime and core-js
exclude: /(@babel(?:\/|\\{1,2})runtime)|(core-js)/,
include: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
// cache
...babelLoaderCacheOptions,
// preset from our own package
presets: getBabelPresets({ hasReact: false }),
// If an error happens in a package, it's possible to be
// because it was compiled. Thus, we don't want the browser
// debugger to show the original code. Instead, the code
// being evaluated would be much more helpful.
sourceMaps: false,
// disable babelrc and babel.config.js for node_modules
configFile: false,
babelrc: false,
},
},
],
};

// Create style rules
const styleRules: webpack.RuleSetRule = {
test: /\.css$/,
Expand Down Expand Up @@ -516,6 +544,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
rules: [
jsRules,
tsRules,
nmJsRules,
styleRules,
fileRulesNonStyle,
fileRulesStyle,
Expand Down

0 comments on commit 9ac03a4

Please sign in to comment.