next-transpile-modules
Advanced tools
Comparing version 6.1.0 to 6.2.0
{ | ||
"name": "next-transpile-modules", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"license": "MIT", | ||
@@ -43,9 +43,9 @@ "author": "Pierre de la Martinière <pierre.de.la.martiniere@gmail.com>", | ||
"dependencies": { | ||
"enhanced-resolve": "^5.3.2", | ||
"enhanced-resolve": "^5.7.0", | ||
"escalade": "^3.1.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest-environment-puppeteer": "4.4.0", | ||
"eslint": "^7.14.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"@types/jest-environment-puppeteer": "4.4.1", | ||
"eslint": "^7.18.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-config-semistandard": "^15.0.1", | ||
@@ -57,3 +57,3 @@ "eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"fs-extra": "^9.0.1", | ||
"fs-extra": "^9.1.0", | ||
"jest": "^26.6.3", | ||
@@ -63,3 +63,3 @@ "jest-environment-node": "^26.6.2", | ||
"jest-puppeteer": "^4.4.0", | ||
"prettier": "^2.2.0", | ||
"prettier": "^2.2.1", | ||
"prettier-eslint": "^12.0.0", | ||
@@ -66,0 +66,0 @@ "puppeteer": "^5.5.0", |
@@ -7,3 +7,2 @@ # Next.js + Transpile `node_modules` | ||
Transpile modules from `node_modules` using the Next.js Babel configuration. | ||
@@ -37,3 +36,3 @@ | ||
Latest version tested: **10.0.0**. | ||
Latest Next.js version tested: **10.0.6**. | ||
@@ -60,8 +59,9 @@ ## Installation | ||
- `debug` Boolean: Display some informative logs in the console (can get noisy!) (default to `false`) | ||
- `unstable_webpack5` Boolean: Enable [Next.js Webpack 5 support](https://nextjs.org/blog/next-9-5#webpack-5-support-beta) (experimental) (default to `false`) | ||
**note:** unstable features may break in any patch or minor release without any warning, be careful! | ||
#### Note on Webpack 5 support | ||
Example: | ||
Since `6.2.0` (with `next@10.0.6`), Webpack 5 support is automatically enabled via the `future.webpack5` flag, but is experimental and may break in any patch or minor release (from both `next` or `next-transpile-modules`) without any warning, be careful! | ||
#### Examples | ||
```js | ||
@@ -98,3 +98,3 @@ // next.config.js | ||
```js | ||
const withTM = require('next-transpile-modules')(['styleguide/components']); | ||
const withTM = require('next-transpile-modules')(['styleguide/node_modules/lodash-es']); | ||
@@ -101,0 +101,0 @@ // ... |
@@ -0,1 +1,9 @@ | ||
/** | ||
* disclaimer: | ||
* | ||
* THIS PLUGIN IS A F*CKING BIG HACK. | ||
* | ||
* don't even try to reason about the quality of the following lines of code. | ||
*/ | ||
const path = require('path'); | ||
@@ -101,2 +109,23 @@ const process = require('process'); | ||
/** | ||
* Matcher function for webpack to decide which modules to transpile | ||
* @param {string[]} modulesToTranspile | ||
* @param {function} logger | ||
*/ | ||
const createWebpackMatcher = (modulesToTranspile, logger = createLogger(false)) => { | ||
return (pathValue) => { | ||
const isNestedNodeModules = (pathValue.match(/node_modules/g) || []).length > 1; | ||
if (isNestedNodeModules) { | ||
return false; | ||
} | ||
return modulesToTranspile.some((modulePath) => { | ||
const transpiled = pathValue.includes(modulePath); | ||
if (transpiled) logger(`transpiled: ${pathValue}`); | ||
return transpiled; | ||
}); | ||
}; | ||
}; | ||
/** | ||
* Transpile modules with Next.js Babel configuration | ||
@@ -111,3 +140,3 @@ * @param {string[]} modules | ||
const resolveSymlinks = options.resolveSymlinks || false; | ||
const isWebpack5 = options.unstable_webpack5 || false; | ||
const isWebpack5 = (nextConfig.future && nextConfig.future.webpack5) || false; | ||
const debug = options.debug || false; | ||
@@ -125,12 +154,4 @@ | ||
// https://webpack.js.org/configuration/module/#ruleinclude | ||
const match = (path) => { | ||
const lastEntry = path.split(`${path.sep}node_modules${path.sep}`).slice(-1)[0]; | ||
const matcher = createWebpackMatcher(modulesPaths, logger); | ||
return modules.some((modulePath) => { | ||
const transpiled = lastEntry.includes(modulePath); | ||
if (transpiled) logger(`transpiled: ${path}`); | ||
return transpiled; | ||
}); | ||
}; | ||
return Object.assign({}, nextConfig, { | ||
@@ -179,4 +200,5 @@ webpack(config, options) { | ||
if (isWebpack5) { | ||
return ({ context, request }, cb) => { | ||
return hasInclude(context, request) ? cb() : external({ context, request }, cb); | ||
return async ({ context, request, getResolve }) => { | ||
if (hasInclude(context, request)) return; | ||
return external({ context, request, getResolve }); | ||
}; | ||
@@ -196,3 +218,3 @@ } | ||
use: options.defaultLoaders.babel, | ||
include: match, | ||
include: matcher, | ||
}); | ||
@@ -209,3 +231,3 @@ | ||
loader: options.defaultLoaders.babel, | ||
include: match, | ||
include: matcher, | ||
}); | ||
@@ -229,3 +251,3 @@ } | ||
if (nextCssLoader) { | ||
nextCssLoader.issuer.or = nextCssLoader.issuer.and ? nextCssLoader.issuer.and.concat(match) : match; | ||
nextCssLoader.issuer.or = nextCssLoader.issuer.and ? nextCssLoader.issuer.and.concat(matcher) : matcher; | ||
delete nextCssLoader.issuer.not; | ||
@@ -238,3 +260,3 @@ delete nextCssLoader.issuer.and; | ||
if (nextSassLoader) { | ||
nextSassLoader.issuer.or = nextSassLoader.issuer.and ? nextSassLoader.issuer.and.concat(match) : match; | ||
nextSassLoader.issuer.or = nextSassLoader.issuer.and ? nextSassLoader.issuer.and.concat(matcher) : matcher; | ||
delete nextSassLoader.issuer.not; | ||
@@ -241,0 +263,0 @@ delete nextSassLoader.issuer.and; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23086
236
Updatedenhanced-resolve@^5.7.0