mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Give up on experimental code splitting
This commit is contained in:
parent
21034834ac
commit
1beab4f5c0
2 changed files with 38 additions and 29 deletions
|
@ -21,7 +21,8 @@ export const getLassoSelectedElementIds = async (
|
||||||
): Promise<
|
): Promise<
|
||||||
LassoWorkerOutput<typeof Commands.GET_LASSO_SELECTED_ELEMENT_IDS>
|
LassoWorkerOutput<typeof Commands.GET_LASSO_SELECTED_ELEMENT_IDS>
|
||||||
> => {
|
> => {
|
||||||
const { Commands, getLassoSelectedElementIds } = await lazyLoadLassoSharedChunk();
|
const { Commands, getLassoSelectedElementIds } =
|
||||||
|
await lazyLoadLassoSharedChunk();
|
||||||
|
|
||||||
const inputWithCommand: LassoWorkerInput = {
|
const inputWithCommand: LassoWorkerInput = {
|
||||||
...input,
|
...input,
|
||||||
|
|
|
@ -16,17 +16,15 @@ const ENV_VARS = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// excludes all external dependencies and bundles only the source code
|
const rawConfigCommon = {
|
||||||
const getConfig = (outdir) => ({
|
|
||||||
outdir,
|
|
||||||
bundle: true,
|
bundle: true,
|
||||||
splitting: true,
|
|
||||||
format: "esm",
|
format: "esm",
|
||||||
packages: "external",
|
|
||||||
plugins: [sassPlugin()],
|
plugins: [sassPlugin()],
|
||||||
target: "es2020",
|
|
||||||
assetNames: "[dir]/[name]",
|
assetNames: "[dir]/[name]",
|
||||||
chunkNames: "[dir]/[name]-[hash]",
|
chunkNames: "[dir]/[name]-[hash]",
|
||||||
|
// chunks are always external, so they are not bundled within and get build separately
|
||||||
|
external: ["*.chunk"],
|
||||||
|
packages: "external",
|
||||||
alias: {
|
alias: {
|
||||||
"@excalidraw/common": path.resolve(__dirname, "../packages/common/src"),
|
"@excalidraw/common": path.resolve(__dirname, "../packages/common/src"),
|
||||||
"@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
|
"@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
|
||||||
|
@ -37,47 +35,57 @@ const getConfig = (outdir) => ({
|
||||||
loader: {
|
loader: {
|
||||||
".woff2": "file",
|
".woff2": "file",
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
function buildDev(config) {
|
const rawConfigIndex = {
|
||||||
return build({
|
...rawConfigCommon,
|
||||||
...config,
|
entryPoints: ["index.tsx"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const rawConfigChunks = {
|
||||||
|
...rawConfigCommon,
|
||||||
|
// create a separate chunk for each
|
||||||
|
entryPoints: ["**/*.chunk.ts"],
|
||||||
|
entryNames: "[name]",
|
||||||
|
};
|
||||||
|
|
||||||
|
function buildDev(chunkConfig) {
|
||||||
|
const config = {
|
||||||
|
...chunkConfig,
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
define: {
|
define: {
|
||||||
"import.meta.env": JSON.stringify(ENV_VARS.development),
|
"import.meta.env": JSON.stringify(ENV_VARS.development),
|
||||||
},
|
},
|
||||||
});
|
outdir: "dist/dev",
|
||||||
|
};
|
||||||
|
|
||||||
|
return build(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildProd(config) {
|
function buildProd(chunkConfig) {
|
||||||
return build({
|
const config = {
|
||||||
...config,
|
...chunkConfig,
|
||||||
minify: true,
|
minify: true,
|
||||||
define: {
|
define: {
|
||||||
"import.meta.env": JSON.stringify(ENV_VARS.production),
|
"import.meta.env": JSON.stringify(ENV_VARS.production),
|
||||||
},
|
},
|
||||||
});
|
outdir: "dist/prod",
|
||||||
|
};
|
||||||
|
|
||||||
|
return build(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createESMRawBuild = async () => {
|
const createESMRawBuild = async () => {
|
||||||
const chunksConfig = {
|
|
||||||
entryPoints: ["index.tsx", "**/*.chunk.ts"],
|
|
||||||
entryNames: "[name]",
|
|
||||||
};
|
|
||||||
|
|
||||||
// development unminified build with source maps
|
// development unminified build with source maps
|
||||||
await buildDev({
|
await buildDev(rawConfigIndex);
|
||||||
...getConfig("dist/dev"),
|
await buildDev(rawConfigChunks);
|
||||||
...chunksConfig,
|
|
||||||
});
|
|
||||||
|
|
||||||
// production minified buld without sourcemaps
|
// production minified buld without sourcemaps
|
||||||
await buildProd({
|
await buildProd(rawConfigIndex);
|
||||||
...getConfig("dist/prod"),
|
await buildProd(rawConfigChunks);
|
||||||
...chunksConfig,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// otherwise throws "ERROR: Could not resolve "./subset-worker.chunk"
|
||||||
(async () => {
|
(async () => {
|
||||||
await createESMRawBuild();
|
await createESMRawBuild();
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue