Skip to content

Commit e87abd6

Browse files
committed
feat(scripts): add cache to babel loader for js and ts
This would default to node_modules/.cache/babel-loader which is a sane default. See #472
1 parent 16f5a3f commit e87abd6

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

examples/plugin/inc/class-wpackio-plugin-init.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public function __construct() {
1717

1818

1919
function plugin_enqueue() {
20-
// $this->enqueue->enqueue( 'app', 'main', [] );
21-
// $this->enqueue->enqueue( 'app', 'mobile', [] );
22-
// $this->enqueue->enqueue( 'foo', 'main', [] );
20+
$this->enqueue->enqueue( 'app', 'main', [] );
21+
$this->enqueue->enqueue( 'app', 'mobile', [] );
22+
$this->enqueue->enqueue( 'foo', 'main', [] );
2323
$this->enqueue->enqueue( 'tsapp', 'main', [] );
2424
}
2525

2626
function reactapp( $atts, $content = null ) {
2727
// Enqueue our react app scripts
28-
// $this->enqueue->enqueue( 'reactapp', 'main', [] );
28+
$this->enqueue->enqueue( 'reactapp', 'main', [] );
2929

3030
// Print the entry point
3131
return '<div id="wpackio-reactapp"></div>';

packages/scripts/src/config/WebpackConfigHelper.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
369369
hasReact,
370370
};
371371

372+
const babelLoaderCacheOptions = {
373+
// This is a feature of `babel-loader` for webpack (not Babel itself).
374+
// It enables caching results in ./node_modules/.cache/babel-loader/
375+
// directory for faster rebuilds.
376+
cacheDirectory: true,
377+
cacheCompression: !this.isDev,
378+
compact: !this.isDev,
379+
};
380+
372381
// check if babel.config.js is present
373382
const isBabelConfigPresent = this.config.useBabelConfig;
374383

@@ -400,7 +409,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
400409
{
401410
loader: 'babel-loader',
402411
options: isBabelConfigPresent
403-
? {}
412+
? { ...babelLoaderCacheOptions }
404413
: this.getOverrideWebpackRuleOptions(
405414
{
406415
presets: jsPresets,
@@ -409,6 +418,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
409418
// rather use the jsBabelOverride
410419
configFile: false,
411420
babelrc: false,
421+
...babelLoaderCacheOptions,
412422
},
413423
this.config.jsBabelOverride
414424
),
@@ -432,7 +442,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
432442
{
433443
loader: 'babel-loader',
434444
options: isBabelConfigPresent
435-
? {}
445+
? { ...babelLoaderCacheOptions }
436446
: this.getOverrideWebpackRuleOptions(
437447
{
438448
presets: tsPresets,
@@ -441,6 +451,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
441451
// rather use the jsBabelOverride
442452
configFile: false,
443453
babelrc: false,
454+
...babelLoaderCacheOptions,
444455
// We don't need plugin-proposal-class-properties
445456
// because taken care of by @wpackio/base
446457
// '@babel/proposal-class-properties',

0 commit comments

Comments
 (0)