mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
run two vite builds for the sdk build, assets & js separately
This commit is contained in:
parent
6add3f1da3
commit
c921091957
11
scripts/sdk/base-manifest.json
Normal file
11
scripts/sdk/base-manifest.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "hydrogen-sdk",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"main": "./hydrogen.cjs.js",
|
||||||
|
"exports": {
|
||||||
|
"import": "./hydrogen.es.js",
|
||||||
|
"require": "./hydrogen.cjs.js"
|
||||||
|
},
|
||||||
|
"files": [],
|
||||||
|
"types": "types/lib.d.ts"
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
yarn run vite build -c vite.sdk-config.js
|
yarn run vite build -c vite.sdk-assets-config.js
|
||||||
|
yarn run vite build -c vite.sdk-lib-config.js
|
||||||
yarn tsc -p tsconfig-declaration.json
|
yarn tsc -p tsconfig-declaration.json
|
||||||
./scripts/sdk/create-manifest.js ./target/package.json
|
./scripts/sdk/create-manifest.js ./target/package.json
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const baseManifest = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
const appManifest = require("../../package.json")
|
||||||
|
const baseSDKManifest = require("./base-manifest.json")
|
||||||
const mergeOptions = require('merge-options');
|
const mergeOptions = require('merge-options');
|
||||||
|
|
||||||
const manifestExtension = {
|
const manifestExtension = {
|
||||||
name: "hydrogen-sdk",
|
|
||||||
main: "./hydrogen.cjs.js",
|
|
||||||
exports: {
|
|
||||||
import: "./hydrogen.es.js",
|
|
||||||
require: "./hydrogen.cjs.js"
|
|
||||||
},
|
|
||||||
files: [],
|
|
||||||
types: "types/lib.d.ts",
|
|
||||||
devDependencies: undefined,
|
devDependencies: undefined,
|
||||||
scripts: undefined,
|
scripts: undefined,
|
||||||
};
|
};
|
||||||
const manifest = mergeOptions(baseManifest, manifestExtension);
|
|
||||||
|
const manifest = mergeOptions(appManifest, baseSDKManifest, manifestExtension);
|
||||||
const json = JSON.stringify(manifest, undefined, 2);
|
const json = JSON.stringify(manifest, undefined, 2);
|
||||||
const outFile = process.argv[2];
|
const outFile = process.argv[2];
|
||||||
fs.writeFileSync(outFile, json, {encoding: "utf8"});
|
fs.writeFileSync(outFile, json, {encoding: "utf8"});
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<!-- this file contains all references to include in the SDK asset build (using vite.sdk-assets-config.js) -->
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
|
||||||
<title></title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="./platform/web/ui/css/main.css">
|
<link rel="stylesheet" type="text/css" href="./platform/web/ui/css/main.css">
|
||||||
<link rel="stylesheet" type="text/css" href="./platform/web/ui/css/themes/element/theme.css">
|
<link rel="stylesheet" type="text/css" href="./platform/web/ui/css/themes/element/theme.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
export * from "./lib.ts";
|
import "./platform/web/sdk/paths/vite.ts";
|
||||||
import downloadSandboxPath from "./platform/web/assets/download-sandbox.html?url";
|
|
||||||
import workerPath from "./platform/web/worker/main.js?url";
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -31,12 +31,3 @@ export {RoomViewModel} from "./domain/session/room/RoomViewModel.js";
|
|||||||
export {RoomView} from "./platform/web/ui/session/room/RoomView.js";
|
export {RoomView} from "./platform/web/ui/session/room/RoomView.js";
|
||||||
export {TimelineViewModel} from "./domain/session/room/timeline/TimelineViewModel.js";
|
export {TimelineViewModel} from "./domain/session/room/timeline/TimelineViewModel.js";
|
||||||
export {TimelineView} from "./platform/web/ui/session/room/TimelineView";
|
export {TimelineView} from "./platform/web/ui/session/room/TimelineView";
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
export * from "./platform/web/ui/css/main.css";
|
|
||||||
// @ts-ignore
|
|
||||||
export * from "./platform/web/ui/css/themes/element/theme.css";
|
|
||||||
// @ts-ignore
|
|
||||||
import _downloadSandboxPath from "./platform/web/assets/download-sandbox.html?url";
|
|
||||||
// @ts-ignore
|
|
||||||
import _workerPath from "./platform/web/worker/main.js?url";
|
|
||||||
|
@ -7,19 +7,10 @@ const version = manifest.version;
|
|||||||
|
|
||||||
const commonOptions = {
|
const commonOptions = {
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
public: false,
|
publicDir: false,
|
||||||
server: {
|
server: {
|
||||||
hmr: false
|
hmr: false
|
||||||
},
|
},
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
// these should only be imported by the base-x package in any runtime code
|
|
||||||
// and works in the browser with a Uint8Array shim,
|
|
||||||
// rather than including a ton of polyfill code
|
|
||||||
"safe-buffer": "./scripts/package-overrides/safe-buffer/index.js",
|
|
||||||
"buffer": "./scripts/package-overrides/buffer/index.js",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
build: {
|
build: {
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
assetsInlineLimit: 0,
|
assetsInlineLimit: 0,
|
||||||
|
@ -9,6 +9,15 @@ export default defineConfig(({mode}) => {
|
|||||||
return mergeOptions(commonOptions, {
|
return mergeOptions(commonOptions, {
|
||||||
root: "src/platform/web",
|
root: "src/platform/web",
|
||||||
base: "./",
|
base: "./",
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
// these should only be imported by the base-x package in any runtime code
|
||||||
|
// and works in the browser with a Uint8Array shim,
|
||||||
|
// rather than including a ton of polyfill code
|
||||||
|
"safe-buffer": "./scripts/package-overrides/safe-buffer/index.js",
|
||||||
|
"buffer": "./scripts/package-overrides/buffer/index.js",
|
||||||
|
}
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
outDir: "../../../target",
|
outDir: "../../../target",
|
||||||
minify: true,
|
minify: true,
|
||||||
|
11
vite.sdk-assets-config.js
Normal file
11
vite.sdk-assets-config.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const mergeOptions = require('merge-options');
|
||||||
|
const commonOptions = require("./vite.common-config.js");
|
||||||
|
|
||||||
|
export default mergeOptions(commonOptions, {
|
||||||
|
root: "src/",
|
||||||
|
base: "./",
|
||||||
|
build: {
|
||||||
|
outDir: "../target/asset-build/",
|
||||||
|
},
|
||||||
|
});
|
@ -1,72 +0,0 @@
|
|||||||
const path = require("path");
|
|
||||||
const mergeOptions = require('merge-options').bind({concatArrays: true});
|
|
||||||
const commonOptions = require("./vite.common-config.js");
|
|
||||||
const manifest = require("./package.json");
|
|
||||||
|
|
||||||
const srcDir = path.join(__dirname, "src/");
|
|
||||||
const modulesDir = path.join(srcDir, "node_modules/");
|
|
||||||
const mocksDir = path.join(srcDir, "mocks/");
|
|
||||||
const fixturesDir = path.join(srcDir, "fixtures/");
|
|
||||||
|
|
||||||
const commonOutput = {
|
|
||||||
// manualChunks: (id) => {
|
|
||||||
// if (id.endsWith("/lib.ts")) {
|
|
||||||
// console.log(id, arguments);
|
|
||||||
// return "es/lib";
|
|
||||||
// }
|
|
||||||
// if (id.startsWith(srcDir)) {
|
|
||||||
// const idPath = id.substring(srcDir.length);
|
|
||||||
// const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf("."));
|
|
||||||
// return pathWithoutExt;
|
|
||||||
// } else {
|
|
||||||
// return "index";
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
chunkFileNames: `[format]/[name].js`,
|
|
||||||
assetFileNames: `assets/[name][extname]`,
|
|
||||||
// important to preserve export names of every module
|
|
||||||
// so we can still override the file and provider alternative impls
|
|
||||||
minifyInternalExports: false,
|
|
||||||
preferConst: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const externalDependencies = Object.keys(manifest.dependencies).concat(Object.keys(manifest.devDependencies)).filter(d => d !== "@matrix-org/olm").map(d => path.join(__dirname, "node_modules", d));
|
|
||||||
console.log("external", externalDependencies);
|
|
||||||
|
|
||||||
export default mergeOptions(commonOptions, {
|
|
||||||
root: "src/",
|
|
||||||
plugins: [
|
|
||||||
{
|
|
||||||
name: "showconfig",
|
|
||||||
buildStart(rollupOptions) {
|
|
||||||
console.dir(rollupOptions, {depth: 100});
|
|
||||||
},
|
|
||||||
resolveId(source, importer) {
|
|
||||||
console.log(source, importer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
build: {
|
|
||||||
minify: false,
|
|
||||||
sourcemap: false,
|
|
||||||
outDir: "../target",
|
|
||||||
rollupOptions: {
|
|
||||||
input: "./src/lib.ts",
|
|
||||||
treeshake: false,
|
|
||||||
external: (id, parentId) => {
|
|
||||||
const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id;
|
|
||||||
const external = externalDependencies.some(d => resolveId.startsWith(d));
|
|
||||||
if (external) {
|
|
||||||
console.log("external", resolveId);
|
|
||||||
}
|
|
||||||
return external;
|
|
||||||
//return !resolveId.startsWith(srcDir);// || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir);
|
|
||||||
},
|
|
||||||
preserveEntrySignatures: "strict",
|
|
||||||
output: [
|
|
||||||
Object.assign({}, commonOutput, {format: "es"}),
|
|
||||||
Object.assign({}, commonOutput, {format: "cjs"}),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
54
vite.sdk-lib-config.js
Normal file
54
vite.sdk-lib-config.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const mergeOptions = require('merge-options');
|
||||||
|
const commonOptions = require("./vite.common-config.js");
|
||||||
|
const manifest = require("./package.json")
|
||||||
|
|
||||||
|
// const srcDir = path.join(__dirname, "src/");
|
||||||
|
// const modulesDir = path.join(srcDir, "node_modules/");
|
||||||
|
// const mocksDir = path.join(srcDir, "mocks/");
|
||||||
|
// const fixturesDir = path.join(srcDir, "fixtures/");
|
||||||
|
|
||||||
|
const externalDependencies = Object.keys(manifest.dependencies)
|
||||||
|
.concat(Object.keys(manifest.devDependencies))
|
||||||
|
.map(d => path.join(__dirname, "node_modules", d));
|
||||||
|
|
||||||
|
export default mergeOptions(commonOptions, {
|
||||||
|
root: "src/",
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: path.resolve(__dirname, 'src/lib.ts'),
|
||||||
|
formats: ["cjs", "es"],
|
||||||
|
fileName: format => `hydrogen.${format}.js`,
|
||||||
|
},
|
||||||
|
minify: false,
|
||||||
|
sourcemap: false,
|
||||||
|
outDir: "../target/lib-build",
|
||||||
|
// don't bundle any dependencies, they should be imported/required
|
||||||
|
rollupOptions: {
|
||||||
|
external(id, parentId) {
|
||||||
|
const isRelativePath = id.startsWith("./") || id.startsWith("../");
|
||||||
|
const isModuleIdentifier = !isRelativePath && !id.startsWith("/");
|
||||||
|
const resolveId = isRelativePath ? path.join(path.dirname(parentId), id) : id;
|
||||||
|
const external = isModuleIdentifier ||
|
||||||
|
externalDependencies.some(d => resolveId.startsWith(d));
|
||||||
|
// resolveId.startsWith(fixturesDir) ||
|
||||||
|
// resolveId.startsWith(mocksDir);
|
||||||
|
return external;
|
||||||
|
},
|
||||||
|
/* don't bundle, so we can override imports per file at build time to replace components */
|
||||||
|
// output: {
|
||||||
|
// manualChunks: (id) => {
|
||||||
|
// if (id.startsWith(srcDir)) {
|
||||||
|
// const idPath = id.substring(srcDir.length);
|
||||||
|
// const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf("."));
|
||||||
|
// return pathWithoutExt;
|
||||||
|
// } else {
|
||||||
|
// return "index";
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// minifyInternalExports: false,
|
||||||
|
// chunkFileNames: "[format]/[name].js"
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user