Skip to content

Commit

Permalink
Merge pull request martpie#152 from ikibalnyi/patch-2
Browse files Browse the repository at this point in the history
Exclude nested node_modules from transpilation
  • Loading branch information
martpie committed Jan 25, 2021
2 parents 3cff3d9 + d49e3ee commit b24290d
Show file tree
Hide file tree
Showing 2 changed files with 6,948 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/next-transpile-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const createLogger = (enable) => {
/**
* Transpile modules with Next.js Babel configuration
* @param {string[]} modules
* @param {{resolveSymlinks?: boolean; debug?: boolean, unstable_webpack5?: boolean}} options
* @param {{resolveSymlinks?: boolean, debug?: boolean, unstable_webpack5?: boolean}} options
*/
const withTmInitializer = (modules = [], options = {}) => {
const withTM = (nextConfig = {}) => {
Expand All @@ -120,12 +120,15 @@ const withTmInitializer = (modules = [], options = {}) => {

// Generate Webpack condition for the passed modules
// https://webpack.js.org/configuration/module/#ruleinclude
const match = (path) =>
modulesPaths.some((modulePath) => {
const transpiled = path.includes(modulePath);
const match = (path) => {
const lastEntry = path.split(`${path.sep}node_modules${path.sep}`).slice(-1)[0];

return modules.some((modulePath) => {
const transpiled = lastEntry.includes(modulePath);
if (transpiled) logger(`transpiled: ${path}`);
return transpiled;
});
};

return Object.assign({}, nextConfig, {
webpack(config, options) {
Expand Down
Loading

0 comments on commit b24290d

Please sign in to comment.