private async createWebpackConfig()

in packages/ice/src/service/webpackServerCompiler/compiler.ts [19:89]


  private async createWebpackConfig(options: {
    userServerConfig: UserConfig['server'];
    rootDir: string;
    [key: string]: any;
  }) {
    const { userServerConfig } = options;
    const { webpackConfig = {} } = userServerConfig;
    const definitions = await this.getEsbuildInject();
    return getWebpackConfig({
      config: {
        mode: 'production',
        entry: options.entryPoints,
        alias: options.alias,
        webpackTarget: 'node12.20',
        externalsPresets: {
          node: false,
        },
        output: {
          filename: `[name].${options.format === 'esm' ? 'mjs' : 'cjs'}`,
          path: options.outdir,
          // align the output with former esbuild
          chunkFormat: false,
          clean: true,
          library: {
            type: 'commonjs2',
          },
          ...(webpackConfig.output as any),
        },
        plugins: [...options.plugins, ...(webpackConfig.plugins || [])] as any,
        externals: options.externals,
        outputDir: options.outdir,
        enableCache: false,
        loaders: [
          // Use esbuild to compile JavaScript & TypeScript
          {
            //   // Match `.js`, `.jsx`, `.ts` or `.tsx` files
            test: /\.m?[jt]sx?$/,
            use: [path.resolve(_dirname, 'removeMagicString.js')],
          },
          ...(webpackConfig.module?.rules || []),
        ],
        useDevServer: false,
        analyzer: false,
        assetsManifest: false,
        define: options.define,
        optimization: { ...webpackConfig.optimization } as any,
        minify: options.minify,
        compileIncludes: webpackConfig.transformInclude,
        swcOptions: {
          compilationConfig: {
            jsc: {
              externalHelpers: false,
              transform: {
                react: {
                  runtime: options.jsx,
                  importSource: '@ice/runtime/react',
                },
              },
            },
          },
        },
        definitions,
      },
      rootDir: options.rootDir,
      webpack: webpack as any,
      runtimeTmpDir: RUNTIME_TMP_DIR,
      userConfigHash: '',
      getExpandedEnvs,
      isServer: true,
    });
  }