feat(plugin-infra): support esm bundler (#3460)

This commit is contained in:
Alex Yang
2023-07-29 12:07:32 -07:00
committed by GitHub
parent 6388a798c9
commit 0b66e911b1
10 changed files with 191 additions and 103 deletions

View File

@@ -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],
},