@forge/bundler

6.1.23-next.56.1.23-next.6
out/config/nativeui.js
~out/config/nativeui.jsModified
+99−59
Index: package/out/config/nativeui.js
===================================================================
--- package/out/config/nativeui.js
+++ package/out/config/nativeui.js
@@ -1,89 +1,129 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getNativeUiBuildConfig = void 0;
+exports.getNativeUiWorkerBuildConfig = exports.getNativeUiBuildConfig = void 0;
 const tslib_1 = require("tslib");
 const path_1 = tslib_1.__importDefault(require("path"));
 const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
 const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
 const cli_shared_1 = require("@forge/cli-shared");
 const common_1 = require("./common");
+const WORKER_OUTPUT_SUBDIR = '__worker__';
+const getBundleAnalyzerPlugin = (statsFilename) => process.env.FORGE_INSPECT_ARCHIVE
+    ? new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
+        analyzerMode: 'disabled',
+        generateStatsFile: true,
+        statsFilename: path_1.default.join(process.cwd(), statsFilename),
+        logLevel: 'silent'
+    })
+    : null;
+const baseNativeUiConfig = {
+    mode: 'production',
+    devtool: 'source-map',
+    node: { __dirname: true },
+    performance: { hints: false },
+    resolve: {
+        extensions: ['.ts', '.tsx', '.js', '.jsx', '.jpg', '.jpeg', '.png', '.gif', '.svg']
+    },
+    resolveLoader: {
+        modules: require.resolve.paths('babel-loader') || undefined
+    },
+    module: {
+        rules: [
+            {
+                test: /\.(jpe?g|png|gif|svg)$/i,
+                type: 'asset/resource'
+            },
+            { test: /\.tsx?$/, loader: 'ts-loader' },
+            {
+                test: /\.jsx?$/,
+                exclude: /node_modules/,
+                use: [
+                    {
+                        loader: 'babel-loader',
+                        options: {
+                            plugins: [
+                                [
+                                    require.resolve('@babel/plugin-transform-react-jsx'),
+                                    {
+                                        pragma: 'React.createElement'
+                                    }
+                                ],
+                                require.resolve('@babel/plugin-transform-numeric-separator'),
+                                require.resolve('@babel/plugin-transform-class-static-block'),
+                                require.resolve('@babel/plugin-transform-class-properties'),
+                                require.resolve('@babel/plugin-transform-optional-chaining')
+                            ],
+                            cacheDirectory: true
+                        }
+                    }
+                ]
+            }
+        ]
+    }
+};
 const getNativeUiBuildConfig = (entrypoints, i18nConfig) => {
     const resolvedEntryPoints = {};
     for (const entrypoint of entrypoints) {
+        if (entrypoint.name === WORKER_OUTPUT_SUBDIR) {
+            throw new Error(`Entry point name "${WORKER_OUTPUT_SUBDIR}" is reserved for the web worker bundle output directory and cannot be used as a resource key.`);
+        }
         resolvedEntryPoints[entrypoint.name] = path_1.default.resolve(entrypoint.path);
     }
     return {
-        entry: {
-            ...resolvedEntryPoints
-        },
+        ...baseNativeUiConfig,
+        entry: { ...resolvedEntryPoints },
         name: 'native-ui',
-        mode: 'production',
-        devtool: 'source-map',
+        target: 'web',
         output: {
             filename: '[name].js',
             path: (0, cli_shared_1.tmpDir)('native-ui'),
             publicPath: 'auto'
         },
-        node: {
-            __dirname: true
-        },
-        performance: {
-            hints: false
-        },
         plugins: [
-            new html_webpack_plugin_1.default({
-                filename: 'index.html'
-            }),
-            process.env.FORGE_INSPECT_ARCHIVE
-                ? new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
-                    analyzerMode: 'disabled',
-                    generateStatsFile: true,
-                    statsFilename: path_1.default.join(process.cwd(), '.forge_app_inspect_stats.json'),
-                    logLevel: 'silent'
-                })
-                : null
+            new html_webpack_plugin_1.default({ filename: 'index.html' }),
+            getBundleAnalyzerPlugin('.forge_app_inspect_stats.json')
         ].filter(Boolean),
+        module: {
+            rules: [...(i18nConfig ? [(0, common_1.geti18nRule)(i18nConfig)] : []), ...baseNativeUiConfig.module.rules]
+        }
+    };
+};
+exports.getNativeUiBuildConfig = getNativeUiBuildConfig;
+const getNativeUiWorkerBuildConfig = (entrypoints, i18nConfig, baseOutputDir) => {
+    const resolvedEntryPoints = {};
+    for (const entrypoint of entrypoints) {
+        resolvedEntryPoints[entrypoint.name] = path_1.default.resolve(entrypoint.path);
+    }
+    return {
+        ...baseNativeUiConfig,
+        entry: { ...resolvedEntryPoints },
+        name: 'native-ui-worker',
+        target: 'webworker',
+        experiments: { outputModule: true },
         resolve: {
-            extensions: ['.ts', '.tsx', '.js', '.jsx', '.jpg', '.jpeg', '.png', '.gif', '.svg']
+            ...baseNativeUiConfig.resolve,
+            alias: {
+                'iframe-resizer': false
+            }
         },
-        resolveLoader: {
-            modules: require.resolve.paths('babel-loader') || undefined
+        output: {
+            filename: '[name].js',
+            path: path_1.default.join(baseOutputDir ?? (0, cli_shared_1.tmpDir)('native-ui'), WORKER_OUTPUT_SUBDIR),
+            module: true
         },
-        target: 'web',
+        optimization: {
+            splitChunks: false,
+            runtimeChunk: false
+        },
+        plugins: [getBundleAnalyzerPlugin('.forge_app_worker_inspect_stats.json')].filter(Boolean),
         module: {
-            rules: [
-                ...(i18nConfig ? [(0, common_1.geti18nRule)(i18nConfig)] : []),
-                {
-                    test: /\.(jpe?g|png|gif|svg)$/i,
-                    type: 'asset/resource'
-                },
-                { test: /\.tsx?$/, loader: 'ts-loader' },
-                {
-                    test: /\.jsx?$/,
-                    exclude: /node_modules/,
-                    use: [
-                        {
-                            loader: 'babel-loader',
-                            options: {
-                                plugins: [
-                                    [
-                                        require.resolve('@babel/plugin-transform-react-jsx'),
-                                        {
-                                            pragma: 'React.createElement'
-                                        }
-                                    ],
-                                    require.resolve('@babel/plugin-transform-numeric-separator'),
-                                    require.resolve('@babel/plugin-transform-class-static-block'),
-                                    require.resolve('@babel/plugin-transform-class-properties'),
-                                    require.resolve('@babel/plugin-transform-optional-chaining')
-                                ],
-                                cacheDirectory: true
-                            }
-                        }
-                    ]
+            rules: [...(i18nConfig ? [(0, common_1.geti18nRule)(i18nConfig)] : []), ...baseNativeUiConfig.module.rules],
+            parser: {
+                javascript: {
+                    dynamicImportMode: 'eager'
                 }
-            ]
+            }
         }
     };
 };
-exports.getNativeUiBuildConfig = getNativeUiBuildConfig;
+exports.getNativeUiWorkerBuildConfig = getNativeUiWorkerBuildConfig;