diff --git a/packages/lexical-playground/vite.config.ts b/packages/lexical-playground/vite.config.ts index e7d96569716..82018c7c74b 100644 --- a/packages/lexical-playground/vite.config.ts +++ b/packages/lexical-playground/vite.config.ts @@ -77,7 +77,7 @@ export default defineConfig(({command}) => { presets: [['@babel/preset-react', {runtime: 'automatic'}]], }), react(), - ...viteCopyExcalidrawAssets('dev'), + ...viteCopyExcalidrawAssets(), viteCopyEsm(), commonjs({ // This is required for React 19 (at least 19.0.0-beta-26f2496093-20240514) diff --git a/packages/lexical-playground/vite.prod.config.ts b/packages/lexical-playground/vite.prod.config.ts index d0e0b0f235e..59c8f368f05 100644 --- a/packages/lexical-playground/vite.prod.config.ts +++ b/packages/lexical-playground/vite.prod.config.ts @@ -70,7 +70,7 @@ export default defineConfig({ presets: [['@babel/preset-react', {runtime: 'automatic'}]], }), react(), - ...viteCopyExcalidrawAssets('prod'), + ...viteCopyExcalidrawAssets(), viteCopyEsm(), commonjs({ // This is required for React 19 (at least 19.0.0-beta-26f2496093-20240514) diff --git a/packages/lexical-playground/viteCopyExcalidrawAssets.ts b/packages/lexical-playground/viteCopyExcalidrawAssets.ts new file mode 100644 index 00000000000..d2b0d95b6b2 --- /dev/null +++ b/packages/lexical-playground/viteCopyExcalidrawAssets.ts @@ -0,0 +1,53 @@ +/** + * 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 {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')], + }, + { + dest: `${assetDir}/locales/`, + src: [path.join(srcDir, 'locales', '*.js')], + }, + ]; + }); + return [ + { + config() { + return { + define: { + 'process.env.EXCALIDRAW_ASSET_PATH': JSON.stringify('/'), + }, + }; + }, + name: 'viteCopyExcalidrawAssets', + }, + ...viteStaticCopy({ + targets, + }), + ]; +}