@weco/next-plugin-transpile-modules
Advanced tools
Comparing version 0.0.2 to 2.0.1
76
index.js
@@ -0,41 +1,73 @@ | ||
const path = require('path'); | ||
/** | ||
* Stolen from https://stackoverflow.com/questions/10776600/testing-for-equality-of-regular-expressions | ||
*/ | ||
function regexEqual (x, y) { | ||
return (x instanceof RegExp) && (y instanceof RegExp) && | ||
(x.source === y.source) && (x.global === y.global) && | ||
(x.ignoreCase === y.ignoreCase) && (x.multiline === y.multiline); | ||
} | ||
/** | ||
* Actual Next.js plugin | ||
*/ | ||
module.exports = (nextConfig = {}) => { | ||
const { transpileModules = [] } = nextConfig; | ||
const includes = transpileModules.map(module => (new RegExp(`${module}(?!.*node_modules)`))); | ||
const excludes = [new RegExp(`node_modules(?!/(${transpileModules.join('|')})(?!.*node_modules))`)]; | ||
const { transpileModules = [] } = nextConfig | ||
const includes = transpileModules.map(module => (new RegExp(`${module}(?!.*node_modules)`))) | ||
const excludes = transpileModules.map(module => (new RegExp(`node_modules(?!\/${module}(?!.*node_modules))`))) | ||
return Object.assign({}, nextConfig, { | ||
webpack(config, options) { | ||
webpack (config, options) { | ||
// Safecheck for Next < 5.0 | ||
if (!options.defaultLoaders) { | ||
throw new Error( | ||
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade' | ||
) | ||
); | ||
} | ||
config.resolve.symlinks = false | ||
// Avoid Webpack to resolve transpiled modules path to their real path | ||
config.resolve.symlinks = false; | ||
config.externals = config.externals.map(external => { | ||
if (typeof external !== 'function') return external | ||
return (ctx, req, cb) => | ||
(Boolean(includes.find(include => include.test(req))) ? cb() : external(ctx, req, cb)) | ||
}) | ||
if (typeof external !== 'function') return external; | ||
return (ctx, req, cb) => { | ||
return includes.find(include => | ||
req.startsWith('.') | ||
? include.test(path.resolve(ctx, req)) | ||
: include.test(req) | ||
) | ||
? cb() | ||
: external(ctx, req, cb); | ||
}; | ||
}); | ||
// Add a rule to include and parse all modules | ||
config.module.rules.push({ | ||
test: /\.+(js|jsx)$/, | ||
test: /\.+(js|jsx|ts|tsx)$/, | ||
loader: options.defaultLoaders.babel, | ||
include: includes | ||
}) | ||
}); | ||
if (typeof nextConfig.webpack === 'function') { | ||
return nextConfig.webpack(config, options) | ||
return nextConfig.webpack(config, options); | ||
} | ||
return config | ||
return config; | ||
}, | ||
webpackDevMiddleware(config) { | ||
const ignored = [config.watchOptions.ignored[0]].concat(excludes) | ||
config.watchOptions.ignored = ignored | ||
return config | ||
// webpackDevMiddleware needs to be told to watch the changes in the | ||
// transpiled modules directories | ||
webpackDevMiddleware (config) { | ||
// Replace /node_modules/ by the new exclude RegExp (including the modules | ||
// that are going to be transpiled) | ||
// https://github.com/zeit/next.js/blob/815f2e91386a0cd046c63cbec06e4666cff85971/packages/next/server/hot-reloader.js#L335 | ||
const ignored = config.watchOptions.ignored.filter( | ||
regexp => !regexEqual(regexp, /[\\/]node_modules[\\/]/) | ||
).concat(excludes); | ||
config.watchOptions.ignored = ignored; | ||
return config; | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
{ | ||
"name": "@weco/next-plugin-transpile-modules", | ||
"version": "0.0.2", | ||
"version": "2.0.1", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"repository": "wellcometrust/next-plugin-transpile-modules", | ||
"author": "Wellcome Collection <digital@wellcomecollection.org>", | ||
"description": "Next.js plugin to transpile code from node_modules (supports TypeScript)", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"lint": "eslint ." | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wellcometrust/next-plugin-transpile-modules.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/wellcometrust/next-plugin-transpile-modules/issues" | ||
}, | ||
"homepage": "https://github.com/wellcometrust/next-plugin-transpile-modules#readme", | ||
"keywords": [ | ||
"next", | ||
"next.js", | ||
"plugin", | ||
"transpile", | ||
"modules", | ||
"babel" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"webpack": "^3.10.0" | ||
"eslint": "5.12.1", | ||
"eslint-config-semistandard": "^13.0.0", | ||
"eslint-config-standard": "12.0.0", | ||
"eslint-plugin-import": "2.15.0", | ||
"eslint-plugin-node": "8.0.1", | ||
"eslint-plugin-promise": "4.0.1", | ||
"eslint-plugin-standard": "4.0.0" | ||
} | ||
} |
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
63
1
1
119
0
8413
7
4