Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-playground] Bug Fix: Use local excalidraw #6861

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/lexical-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"@vitejs/plugin-react": "^4.2.1",
"rollup-plugin-copy": "^3.5.0",
"vite": "^5.2.11",
"vite-plugin-replace": "^0.1.1"
"vite-plugin-replace": "^0.1.1",
"vite-plugin-static-copy": "^2.1.0"
},
"sideEffects": false
}
4 changes: 4 additions & 0 deletions packages/lexical-playground/src/setupEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ export default (() => {
// @ts-expect-error
delete window.InputEvent.prototype.getTargetRanges;
}

// @ts-ignore
window.EXCALIDRAW_ASSET_PATH = process.env.EXCALIDRAW_ASSET_PATH;

return INITIAL_SETTINGS;
})();
2 changes: 2 additions & 0 deletions packages/lexical-playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {replaceCodePlugin} from 'vite-plugin-replace';

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

const require = createRequire(import.meta.url);

Expand Down Expand Up @@ -76,6 +77,7 @@ export default defineConfig(({command}) => {
presets: [['@babel/preset-react', {runtime: 'automatic'}]],
}),
react(),
...viteCopyExcalidrawAssets(),
viteCopyEsm(),
commonjs({
// This is required for React 19 (at least 19.0.0-beta-26f2496093-20240514)
Expand Down
2 changes: 2 additions & 0 deletions packages/lexical-playground/vite.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {replaceCodePlugin} from 'vite-plugin-replace';

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

// https://vitejs.dev/config/
export default defineConfig({
Expand Down Expand Up @@ -69,6 +70,7 @@ export default defineConfig({
presets: [['@babel/preset-react', {runtime: 'automatic'}]],
}),
react(),
...viteCopyExcalidrawAssets(),
viteCopyEsm(),
commonjs({
// This is required for React 19 (at least 19.0.0-beta-26f2496093-20240514)
Expand Down
56 changes: 56 additions & 0 deletions packages/lexical-playground/viteCopyExcalidrawAssets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import type {Plugin} from 'vite';

import {createRequire} from 'node:module';
import * as path from 'node:path';
import {normalizePath} from 'vite';
import {Target, viteStaticCopy} from 'vite-plugin-static-copy';

const require = createRequire(import.meta.url);

export default function viteCopyExcalidrawAssets(): Plugin[] {
const targets: Target[] = [
'excalidraw-assets',
'excalidraw-assets-dev',
].flatMap((assetDir) => {
const srcDir = path.join(
require.resolve('@excalidraw/excalidraw'),
'..',
'dist',
assetDir,
);
return [
{
dest: `${assetDir}/`,
src: [path.join(srcDir, '*.js'), path.join(srcDir, '*.woff2')].map(
normalizePath,
),
},
{
dest: `${assetDir}/locales/`,
src: [path.join(srcDir, 'locales', '*.js')].map(normalizePath),
},
];
});
return [
{
config() {
return {
define: {
'process.env.EXCALIDRAW_ASSET_PATH': JSON.stringify('/'),
},
};
},
name: 'viteCopyExcalidrawAssets',
},
...viteStaticCopy({
targets,
}),
];
}
3 changes: 2 additions & 1 deletion packages/shared/viteModuleResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
NpmModuleExportEntry,
PackageMetadata,
} from '../../scripts/shared/PackageMetadata';
import type {Alias} from 'vite';

import * as fs from 'node:fs';
import {createRequire} from 'node:module';
Expand Down Expand Up @@ -81,7 +82,7 @@ const distModuleResolution = (environment: 'development' | 'production') => {

export default function moduleResolution(
environment: 'source' | 'development' | 'production',
) {
): Alias[] {
return environment === 'source'
? sourceModuleResolution()
: distModuleResolution(environment);
Expand Down
Loading