(
pkg: Package,
entry: string | Record<string, string>,
htmlConfig: Partial<CreateHTMLPluginConfig> = {},
deps?: string[]
)
| 43 | } |
| 44 | |
| 45 | export function createHTMLTargetConfig( |
| 46 | pkg: Package, |
| 47 | entry: string | Record<string, string>, |
| 48 | htmlConfig: Partial<CreateHTMLPluginConfig> = {}, |
| 49 | deps?: string[] |
| 50 | ): webpack.Configuration { |
| 51 | entry = typeof entry === 'string' ? { index: entry } : entry; |
| 52 | |
| 53 | htmlConfig = merge( |
| 54 | {}, |
| 55 | { |
| 56 | filename: 'index.html', |
| 57 | additionalEntryForSelfhost: true, |
| 58 | injectGlobalErrorHandler: true, |
| 59 | emitAssetsManifest: true, |
| 60 | }, |
| 61 | htmlConfig |
| 62 | ); |
| 63 | |
| 64 | const buildConfig = getBuildConfigFromEnv(pkg); |
| 65 | |
| 66 | console.log( |
| 67 | `Building [${pkg.name}] for [${buildConfig.appBuildType}] channel in [${buildConfig.debug ? 'development' : 'production'}] mode.` |
| 68 | ); |
| 69 | console.log( |
| 70 | `Entry points: ${Object.entries(entry) |
| 71 | .map(([name, path]) => `${name}: ${path}`) |
| 72 | .join(', ')}` |
| 73 | ); |
| 74 | console.log(`Output path: ${pkg.distPath.value}`); |
| 75 | console.log(`Config: ${JSON.stringify(buildConfig, null, 2)}`); |
| 76 | |
| 77 | const config: webpack.Configuration = { |
| 78 | //#region basic webpack config |
| 79 | name: entry['index'], |
| 80 | dependencies: deps, |
| 81 | context: ProjectRoot.value, |
| 82 | experiments: { |
| 83 | topLevelAwait: true, |
| 84 | outputModule: false, |
| 85 | syncWebAssembly: true, |
| 86 | }, |
| 87 | entry, |
| 88 | output: { |
| 89 | environment: { module: true, dynamicImport: true }, |
| 90 | filename: buildConfig.debug |
| 91 | ? 'js/[name].js' |
| 92 | : 'js/[name].[contenthash:8].js', |
| 93 | assetModuleFilename: buildConfig.debug |
| 94 | ? '[name].[contenthash:8][ext]' |
| 95 | : 'assets/[name].[contenthash:8][ext][query]', |
| 96 | path: pkg.distPath.value, |
| 97 | clean: false, |
| 98 | globalObject: 'globalThis', |
| 99 | // NOTE(@forehalo): always keep it '/' |
| 100 | publicPath: '/', |
| 101 | }, |
| 102 | target: ['web', 'es2022'], |
nothing calls this directly
no test coverage detected