diff --git a/packages/svelte-view360/build.js b/packages/svelte-view360/build.js index 9e65ac2f..cb0c929f 100644 --- a/packages/svelte-view360/build.js +++ b/packages/svelte-view360/build.js @@ -1,11 +1,13 @@ +/* eslint-env node */ const path = require("path"); const fs = require("fs-extra"); const svelte = require("svelte/compiler"); -const { typescript } = require("svelte-preprocess"); +const { typescript, replace } = require("svelte-preprocess"); const ts = require("typescript"); const tsconfig = require("./tsconfig.json"); +const replaces = require("./replace.cjs"); const files = fs.readdirSync(path.resolve(__dirname, "./src"), { withFileTypes: true }); @@ -42,7 +44,8 @@ svelteFiles.forEach(async fileName => { tsconfigDirectory: ".", tsconfigFile: "./tsconfig.json", handleMixedImports: true - }) + }), + replace(replaces) ], { filename: fileName }); diff --git a/packages/svelte-view360/replace.cjs.js b/packages/svelte-view360/replace.cjs.js new file mode 100644 index 00000000..ce1d1d27 --- /dev/null +++ b/packages/svelte-view360/replace.cjs.js @@ -0,0 +1,17 @@ +/* eslint-env node */ +const View360 = require("@egjs/view360"); + +const options = Object.getOwnPropertyNames(View360.prototype) + .filter(name => { + const descriptor = Object.getOwnPropertyDescriptor(View360.prototype, name); + + if (name.startsWith("_")) return false; + if (descriptor?.value) return false; + + return true; + }); + +module.exports = [ + ["// @ts-ignore", ""], + ["__DECLARE_PROPS__", options.map(opt => `export let ${opt} = undefined;`).join("\n")] +]; diff --git a/packages/svelte-view360/replace.js b/packages/svelte-view360/replace.js index 1bbbd618..c05625d4 100644 --- a/packages/svelte-view360/replace.js +++ b/packages/svelte-view360/replace.js @@ -11,5 +11,6 @@ const options = Object.getOwnPropertyNames(View360.prototype) }); export default [ + ["// @ts-ignore", ""], ["__DECLARE_PROPS__", options.map(opt => `export let ${opt} = undefined;`).join("\n")] ];