Skip to content

Commit

Permalink
Use build artifacts not typescript sources for playground build
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed May 3, 2024
1 parent b7159dd commit f591d14
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"start-test-server": "npm run preview --prefix packages/lexical-playground -- --port 4000",
"build": "node scripts/build.js",
"build-prod": "npm run clean && npm run build -- --prod",
"build-playground-prod": "npm run build-prod && npm run build-prod --prefix packages/lexical-playground",
"build-playground-prod": "npm run build && npm run build-prod --prefix packages/lexical-playground",
"build-release": "npm run build-prod -- --release",
"build-www": "npm run clean && npm run build -- --www && npm run build -- --www --prod && npm run prepare-www",
"build-types": "tsc -p ./tsconfig.build.json && node ./scripts/validate-tsc-types.js",
Expand Down
40 changes: 39 additions & 1 deletion packages/lexical-playground/vite.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,49 @@
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import react from '@vitejs/plugin-react';
import * as fs from 'node:fs';
import {createRequire} from 'node:module';
import * as path from 'node:path';
import {defineConfig} from 'vite';
import {replaceCodePlugin} from 'vite-plugin-replace';

import moduleResolution from '../shared/viteModuleResolution';
import viteCopyEsm from './viteCopyEsm';

const require = createRequire(import.meta.url);
const {packagesManager} =
require('../../scripts/shared/packagesManager') as typeof import('../../scripts/shared/packagesManager');

const moduleResolution = [
...packagesManager.getPublicPackages().flatMap((pkg) =>
pkg.getNormalizedNpmModuleExportEntries().map(([find, exports]) => {
// Prefer the development esm version because we want nice errors and
// introspection on the playground!
const replacements = (['development', 'default'] as const).map((k) =>
pkg.resolve('dist', exports.import[k]),
);
const replacement = replacements.find((fn) => fs.existsSync(fn));
if (!replacement) {
throw new Error(
`ERROR: Missing ./${path.relative(
'../..',
replacements[1],
)}. Did you run \`npm run build\` in the monorepo first?`,
);
}
return {
find,
replacement,
};
}),
),
...[packagesManager.getPackageByDirectoryName('shared')].flatMap((pkg) =>
pkg.getPrivateModuleEntries().map(({name, sourceFileName}) => ({
find: name,
replacement: pkg.resolve('src', sourceFileName),
})),
),
];

// https://vitejs.dev/config/
export default defineConfig({
build: {
Expand All @@ -40,6 +77,7 @@ export default defineConfig({
compress: {
toplevel: true,
},
keep_classnames: true,
},
},
define: {
Expand Down
4 changes: 3 additions & 1 deletion scripts/shared/PackageMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const npmToWwwName = require('../www/npmToWwwName');
*/

/**
* @typedef {readonly [string, Record<'import'|'require', Object>]} NpmModuleExportEntry
* @typedef {Record<'types' | 'development' | 'production' | 'node' | 'default', string>} ImportCondition
* @typedef {Record<'types' | 'development' | 'production' | 'default', string>} RequireCondition
* @typedef {readonly [string, { import: ImportCondition; require: RequireCondition }]} NpmModuleExportEntry
*/

/**
Expand Down

0 comments on commit f591d14

Please sign in to comment.