Просмотр исходного кода

detect local packages and transpile with next-transpile-modules

Yuki Takei 3 лет назад
Родитель
Сommit
a8af88f64a
2 измененных файлов с 34 добавлено и 5 удалено
  1. 3 5
      packages/app/next.config.js
  2. 31 0
      packages/app/src/utils/next.config.utils.js

+ 3 - 5
packages/app/next.config.js

@@ -1,10 +1,8 @@
-import packageJSON from './package.json';
+import { listScopedPackages } from './src/utils/next.config.utils';
 
 // define transpiled packages for '@growi/*'
-const withTM = require('next-transpile-modules')([
-  '@growi/core',
-  '@growi/ui',
-]);
+const scopedPackages = listScopedPackages(['@growi']);
+const withTM = require('next-transpile-modules')(scopedPackages);
 
 // define additional entries
 const additionalWebpackEntries = {

+ 31 - 0
packages/app/src/utils/next.config.utils.js

@@ -0,0 +1,31 @@
+// workaround by https://github.com/martpie/next-transpile-modules/issues/143#issuecomment-817467144
+
+const path = require('path')
+const fs = require('fs')
+
+const node_modules = path.resolve(__dirname, '../../../../node_modules')
+
+
+export const listScopedPackages = (scopes) => {
+  const scopedPackages = []
+
+  fs.readdirSync(node_modules)
+    .filter((name) => scopes.includes(name))
+    .forEach((scope) => {
+      fs.readdirSync(path.resolve(node_modules, scope))
+        .filter((name) => !name.startsWith('.'))
+        .forEach((folderName) => {
+          const { name, ignoreTranspileModules } = require(path.resolve(
+            node_modules,
+            scope,
+            folderName,
+            'package.json'
+          ))
+          if (!ignoreTranspileModules) {
+            scopedPackages.push(name)
+          }
+        })
+    })
+
+  return scopedPackages;
+}