Skip to content

Commit

Permalink
fix: replace in svelte build result
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodNeck authored May 18, 2023
1 parent 7dfb40a commit af682b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/svelte-view360/build.js
Original file line number Diff line number Diff line change
@@ -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 });

Expand Down Expand Up @@ -42,7 +44,8 @@ svelteFiles.forEach(async fileName => {
tsconfigDirectory: ".",
tsconfigFile: "./tsconfig.json",
handleMixedImports: true
})
}),
replace(replaces)
], {
filename: fileName
});
Expand Down
17 changes: 17 additions & 0 deletions packages/svelte-view360/replace.cjs.js
Original file line number Diff line number Diff line change
@@ -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")]
];
1 change: 1 addition & 0 deletions packages/svelte-view360/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
];

0 comments on commit af682b6

Please sign in to comment.