2023-07-18 19:53:10 +03:00
|
|
|
import { createConfiguration, rootPath } from './config.js';
|
|
|
|
import { merge } from 'webpack-merge';
|
2023-08-03 04:48:35 +03:00
|
|
|
import { join, resolve } from 'node:path';
|
2023-07-18 19:53:10 +03:00
|
|
|
import type { BuildFlags } from '@affine/cli/config';
|
|
|
|
import { getRuntimeConfig } from './runtime-config.js';
|
2023-08-03 04:48:35 +03:00
|
|
|
import HTMLPlugin from 'html-webpack-plugin';
|
2023-07-18 19:53:10 +03:00
|
|
|
|
|
|
|
export default async function (cli_env: any, _: any) {
|
|
|
|
const flags: BuildFlags = JSON.parse(
|
|
|
|
Buffer.from(cli_env.flags, 'hex').toString('utf-8')
|
|
|
|
);
|
|
|
|
console.log('build flags', flags);
|
|
|
|
const runtimeConfig = getRuntimeConfig(flags);
|
|
|
|
console.log('runtime config', runtimeConfig);
|
|
|
|
const config = createConfiguration(flags, runtimeConfig);
|
|
|
|
return merge(config, {
|
|
|
|
entry: {
|
2023-08-11 20:14:09 +03:00
|
|
|
'polyfill/intl-segmenter': {
|
|
|
|
import: resolve(rootPath, 'src/polyfill/intl-segmenter.ts'),
|
|
|
|
},
|
2023-08-04 02:05:46 +03:00
|
|
|
'polyfill/ses': {
|
2023-07-30 09:34:52 +03:00
|
|
|
import: resolve(rootPath, 'src/polyfill/ses.ts'),
|
2023-07-18 19:53:10 +03:00
|
|
|
},
|
2023-07-19 12:58:51 +03:00
|
|
|
plugin: {
|
2023-08-11 20:14:09 +03:00
|
|
|
dependOn: ['polyfill/intl-segmenter', 'polyfill/ses'],
|
2023-07-19 12:58:51 +03:00
|
|
|
import: resolve(rootPath, 'src/bootstrap/register-plugins.ts'),
|
|
|
|
},
|
2023-08-04 02:05:46 +03:00
|
|
|
app: {
|
|
|
|
chunkLoading: 'import',
|
2023-08-11 20:14:09 +03:00
|
|
|
dependOn: ['polyfill/intl-segmenter', 'polyfill/ses', 'plugin'],
|
2023-07-30 09:34:52 +03:00
|
|
|
import: resolve(rootPath, 'src/index.tsx'),
|
|
|
|
},
|
2023-08-03 04:48:35 +03:00
|
|
|
'_plugin/index.test': {
|
2023-08-04 02:05:46 +03:00
|
|
|
chunkLoading: 'import',
|
2023-08-11 20:14:09 +03:00
|
|
|
dependOn: ['polyfill/intl-segmenter', 'polyfill/ses', 'plugin'],
|
2023-08-03 04:48:35 +03:00
|
|
|
import: resolve(rootPath, 'src/_plugin/index.test.tsx'),
|
|
|
|
},
|
2023-07-18 19:53:10 +03:00
|
|
|
},
|
2023-08-03 04:48:35 +03:00
|
|
|
plugins: [
|
|
|
|
new HTMLPlugin({
|
|
|
|
template: join(rootPath, '.webpack', 'template.html'),
|
|
|
|
inject: 'body',
|
|
|
|
scriptLoading: 'module',
|
|
|
|
minify: false,
|
2023-08-11 20:14:09 +03:00
|
|
|
chunks: ['app', 'plugin', 'polyfill/intl-segmenter', 'polyfill/ses'],
|
2023-08-03 04:48:35 +03:00
|
|
|
filename: 'index.html',
|
|
|
|
}),
|
|
|
|
new HTMLPlugin({
|
|
|
|
template: join(rootPath, '.webpack', 'template.html'),
|
|
|
|
inject: 'body',
|
|
|
|
scriptLoading: 'module',
|
|
|
|
minify: false,
|
2023-08-11 20:14:09 +03:00
|
|
|
chunks: [
|
|
|
|
'_plugin/index.test',
|
|
|
|
'plugin',
|
|
|
|
'polyfill/intl-segmenter',
|
|
|
|
'polyfill/ses',
|
|
|
|
],
|
2023-08-03 04:48:35 +03:00
|
|
|
filename: '_plugin/index.html',
|
|
|
|
}),
|
|
|
|
],
|
2023-07-18 19:53:10 +03:00
|
|
|
});
|
|
|
|
}
|