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

Fix .cjs importing via webpack/babel (#11090)

GitOrigin-RevId: 62f17069a3e0fd338269fe772a51870222c2877a
Alf Eaton 3 лет назад
Родитель
Сommit
edbe12b86f
2 измененных файлов с 13 добавлено и 5 удалено
  1. 8 1
      services/web/babel.config.json
  2. 5 4
      services/web/webpack.config.js

+ 8 - 1
services/web/babel.config.json

@@ -11,5 +11,12 @@
     ["@babel/react", { "runtime": "automatic" }],
     "@babel/typescript"
   ],
-  "plugins": ["angularjs-annotate", "macros"]
+  "plugins": ["angularjs-annotate", "macros"],
+  "overrides": [
+    // treat .cjs files (e.g. libraries symlinked into node_modules) as commonjs
+    {
+      "test": "../../**/*.cjs",
+      "sourceType": "script"
+    }
+  ]
 }

+ 5 - 4
services/web/webpack.config.js

@@ -91,10 +91,11 @@ module.exports = {
   module: {
     rules: [
       {
-        // Pass application JS/TS files through babel-loader, compiling to ES5
-        test: /\.[jt]sx?$/,
-        // Only compile application files (npm and vendored dependencies are in
-        // ES5 already)
+        // Pass application JS/TS files through babel-loader,
+        // transpiling to targets defined in browserslist
+        test: /\.([jt]sx?|[cm]js)$/,
+        // Only compile application files and specific dependencies
+        // (other npm and vendored dependencies must be in ES5 already)
         exclude: [/node_modules\/(?!(react-dnd|chart\.js)\/)/, vendorDir],
         use: [
           {