Skip to content

Commit 4fa9aff

Browse files
author
Jannik Zschiesche
committed
WE NEED TO GO BACK: include list for npm packages compilation
The exclude list is a can of worms, as this list is endless..
1 parent 122004c commit 4fa9aff

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* (improvement) The code is now always compiled per entry file
3535
* (improvement) Build TypeScript for the `esnext` module system, that (amongst other things) allows to use `import()`.
3636
* (bug) Compile every entry into a separate directory, to avoid issues with the clean plugin.
37-
* (bc) Now you can defined which packages in `node_modules` should NOT be transformed. Use `.ignoreNpmPackages(...)`.
37+
* (bc) Not all npm packages are automatically transpiled anymore. You need to define which packages from `node_modules` to transpile via Babel by using `.compileNpmPackages(...)`.
3838
* (feature) Even if not recommended (use SCSS!), we now support compiling CSS via webpack (not as entry point though). The CSS will be injected into the head dynamically.
3939

4040

src/Kaba.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ProgressBarPlugin = require('progress-bar-webpack-plugin');
1212
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
1313

1414
const PACKAGE_MATCHER = /\/node_modules\/(?<package>(?:@[^@\/]+\/)?[^@\/]+)\//;
15-
type IgnoredNpmPackagesMapping = Array<RegExp|string>;
15+
type CompiledNpmPackagesMapping = Array<RegExp|string>;
1616
const ignoredPackagesCache: {[k: string]: boolean} = {};
1717
interface PostCssLoaderOptions {[key: string]: any}
1818

@@ -36,7 +36,7 @@ interface Externals
3636
/**
3737
* Determines whether a file should processed by the asset pipeline.
3838
*/
39-
function isAllowedPath (path: string, ignoredPackages: IgnoredNpmPackagesMapping) : boolean
39+
function isAllowedPath (path: string, compiledPackages: CompiledNpmPackagesMapping) : boolean
4040
{
4141
const match = PACKAGE_MATCHER.exec(path);
4242

@@ -53,25 +53,25 @@ function isAllowedPath (path: string, ignoredPackages: IgnoredNpmPackagesMapping
5353
return ignoredPackagesCache[packageNameToCompile];
5454
}
5555

56-
const length = ignoredPackages.length;
56+
const length = compiledPackages.length;
5757
for (let i = 0; i < length; ++i)
5858
{
59-
const ignoredPackage = ignoredPackages[i];
59+
const compiledPackage = compiledPackages[i];
6060

61-
if (typeof ignoredPackage == "string")
61+
if (typeof compiledPackage == "string")
6262
{
63-
if (ignoredPackage === packageNameToCompile)
63+
if (compiledPackage === packageNameToCompile)
6464
{
65-
return ignoredPackagesCache[packageNameToCompile] = false;
65+
return ignoredPackagesCache[packageNameToCompile] = true;
6666
}
6767
}
68-
else if (ignoredPackage.test(packageNameToCompile))
68+
else if (compiledPackage.test(packageNameToCompile))
6969
{
70-
return ignoredPackagesCache[packageNameToCompile] = false;
70+
return ignoredPackagesCache[packageNameToCompile] = true;
7171
}
7272
}
7373

74-
return ignoredPackagesCache[packageNameToCompile] = true;
74+
return ignoredPackagesCache[packageNameToCompile] = false;
7575
}
7676

7777
/**
@@ -96,11 +96,10 @@ export class Kaba
9696
private hashFileNames: boolean = true;
9797
private buildModern: boolean = true;
9898
private nodeSettings: webpack.Node|false = false;
99-
private ignoredNpmPackages: IgnoredNpmPackagesMapping = [
100-
/^@babel/,
101-
/^babel-/,
102-
/^core-js(-|$)/,
103-
/^regenerator-/,
99+
private compiledNpmPackages: CompiledNpmPackagesMapping = [
100+
/^@becklyn/,
101+
/^@mayd/,
102+
/^mojave/,
104103
];
105104
private postCssLoaderOptions: PostCssLoaderOptions = {};
106105

@@ -129,11 +128,11 @@ export class Kaba
129128

130129

131130
/**
132-
* Defines which npm packages are NOT compiled with babel
131+
* Defines which npm packages are compiled with babel.
133132
*/
134-
public ignoreNpmPackages (modules: Array<string|RegExp>): this
133+
public compileNpmPackages (modules: Array<string|RegExp>): this
135134
{
136-
this.ignoredNpmPackages = this.ignoredNpmPackages.concat(modules);
135+
this.compiledNpmPackages = this.compiledNpmPackages.concat(modules);
137136
return this;
138137
}
139138

@@ -438,14 +437,14 @@ export class Kaba
438437
},
439438
},
440439
],
441-
include: (path: string) => isAllowedPath(path, this.ignoredNpmPackages),
440+
include: (path: string) => isAllowedPath(path, this.compiledNpmPackages),
442441
},
443442

444443
// Babel
445444
{
446445
test: /\.m?jsx?$/,
447446
use: [babelLoader],
448-
include: (path: string) => isAllowedPath(path, this.ignoredNpmPackages),
447+
include: (path: string) => isAllowedPath(path, this.compiledNpmPackages),
449448
},
450449

451450
// content files

0 commit comments

Comments
 (0)