mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
feat(plugin-infra): support esm bundler (#3460)
This commit is contained in:
@@ -3,6 +3,7 @@ import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { parseArgs } from 'node:util';
|
||||
|
||||
import { StaticModuleRecord } from '@endo/static-module-record';
|
||||
import {
|
||||
packageJsonInputSchema,
|
||||
packageJsonOutputSchema,
|
||||
@@ -52,6 +53,9 @@ const external = [
|
||||
// store
|
||||
/^jotai/,
|
||||
|
||||
// utils
|
||||
'swr',
|
||||
|
||||
// css
|
||||
/^@vanilla-extract/,
|
||||
|
||||
@@ -132,7 +136,7 @@ await build({
|
||||
lib: {
|
||||
entry: coreEntry,
|
||||
fileName: 'index',
|
||||
formats: ['cjs'],
|
||||
formats: ['es'],
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
@@ -152,6 +156,28 @@ await build({
|
||||
plugins: [
|
||||
vanillaExtractPlugin(),
|
||||
react(),
|
||||
{
|
||||
name: 'parse-bundle',
|
||||
renderChunk(code, chunk) {
|
||||
if (chunk.fileName.endsWith('.mjs')) {
|
||||
const record = new StaticModuleRecord(code, chunk.fileName);
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: 'analysis.json',
|
||||
source: JSON.stringify(
|
||||
{
|
||||
exports: record.exports,
|
||||
imports: record.imports,
|
||||
},
|
||||
null,
|
||||
2
|
||||
),
|
||||
});
|
||||
return record.__syncModuleProgram__;
|
||||
}
|
||||
return code;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'generate-package.json',
|
||||
async generateBundle() {
|
||||
@@ -162,7 +188,7 @@ await build({
|
||||
affinePlugin: {
|
||||
release: json.affinePlugin.release,
|
||||
entry: {
|
||||
core: 'index.js',
|
||||
core: 'index.mjs',
|
||||
},
|
||||
assets: [...metadata.assets],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user