Merge pull request #2244 from dolanmiu/feature/build-fixes
Fix `vite` build issues
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="../build/index.umd.cjs"></script>
|
||||
<script src="../build/index.umd.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
||||
</head>
|
||||
|
||||
|
@ -5,9 +5,9 @@ import inquirer from "inquirer";
|
||||
import { $ } from "execa";
|
||||
|
||||
export type Answers = {
|
||||
type: "list" | "number";
|
||||
demoNumber?: number;
|
||||
demoFile?: number;
|
||||
readonly type: "list" | "number";
|
||||
readonly demoNumber?: number;
|
||||
readonly demoFile?: number;
|
||||
};
|
||||
|
||||
const dir = "./demo";
|
||||
@ -15,8 +15,7 @@ const fileNames = fs.readdirSync(dir);
|
||||
|
||||
const keys = fileNames.map((f) => path.parse(f).name);
|
||||
const getFileNumber = (file: string): number => {
|
||||
const nameParts = file.split("-");
|
||||
const firstPart = nameParts[0];
|
||||
const [firstPart] = file.split("-");
|
||||
|
||||
return Number(firstPart);
|
||||
};
|
||||
@ -35,15 +34,15 @@ const answers = await inquirer.prompt<Answers>([
|
||||
name: "demoFile",
|
||||
message: "What demo do you wish to run?",
|
||||
choices: demoFiles,
|
||||
filter: (input) => parseInt(input.split("-")[0]),
|
||||
when: (answers) => answers.type === "list",
|
||||
filter: (input) => parseInt(input.split("-")[0], 10),
|
||||
when: (a) => a.type === "list",
|
||||
},
|
||||
{
|
||||
type: "number",
|
||||
name: "demoNumber",
|
||||
message: "What demo do you wish to run? (Enter a number)",
|
||||
default: 1,
|
||||
when: (answers) => answers.type === "number",
|
||||
when: (a) => a.type === "number",
|
||||
},
|
||||
]);
|
||||
|
||||
@ -56,6 +55,7 @@ if (files.length === 0) {
|
||||
const filePath = path.join(dir, files[0]);
|
||||
|
||||
console.log(`Running demo ${demoNumber}: ${files[0]}`);
|
||||
await $`ts-node --project demo/tsconfig.json ${filePath}`;
|
||||
const { stdout } = await $`ts-node --project demo/tsconfig.json ${filePath}`;
|
||||
console.log(stdout);
|
||||
console.log("Successfully created document!");
|
||||
}
|
||||
|
11
package-lock.json
generated
11
package-lock.json
generated
@ -10,7 +10,6 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "^20.3.1",
|
||||
"fflate": "^0.8.0",
|
||||
"jszip": "^3.10.1",
|
||||
"nanoid": "^4.0.2",
|
||||
"xml": "^1.0.1",
|
||||
@ -5975,11 +5974,6 @@
|
||||
"reusify": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/fflate": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.0.tgz",
|
||||
"integrity": "sha512-FAdS4qMuFjsJj6XHbBaZeXOgaypXp8iw/Tpyuq/w3XA41jjLHT8NPA+n7czH/DDhdncq0nAyDZmPeWXh2qmdIg=="
|
||||
},
|
||||
"node_modules/figlet": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/figlet/-/figlet-1.5.2.tgz",
|
||||
@ -16784,11 +16778,6 @@
|
||||
"reusify": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"fflate": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.0.tgz",
|
||||
"integrity": "sha512-FAdS4qMuFjsJj6XHbBaZeXOgaypXp8iw/Tpyuq/w3XA41jjLHT8NPA+n7czH/DDhdncq0nAyDZmPeWXh2qmdIg=="
|
||||
},
|
||||
"figlet": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/figlet/-/figlet-1.5.2.tgz",
|
||||
|
@ -3,13 +3,13 @@
|
||||
"version": "8.2.0",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"type": "module",
|
||||
"main": "build/index.umd.cjs",
|
||||
"main": "build/index.umd.js",
|
||||
"module": "./build/index.js",
|
||||
"types": "./build/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"browser": {
|
||||
"default": "./build/index.umd.cjs"
|
||||
"default": "./build/index.umd.js"
|
||||
},
|
||||
"require": "./build/index.cjs",
|
||||
"types": "./build/index.d.ts",
|
||||
@ -58,7 +58,6 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/node": "^20.3.1",
|
||||
"fflate": "^0.8.0",
|
||||
"jszip": "^3.10.1",
|
||||
"nanoid": "^4.0.2",
|
||||
"xml": "^1.0.1",
|
||||
|
@ -53,7 +53,7 @@ export interface PatchDocumentOptions {
|
||||
|
||||
const imageReplacer = new ImageReplacer();
|
||||
|
||||
export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Buffer> => {
|
||||
export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Uint8Array> => {
|
||||
const zipContent = await JSZip.loadAsync(data);
|
||||
const contexts = new Map<string, IContext>();
|
||||
const file = {
|
||||
@ -213,7 +213,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
|
||||
}
|
||||
|
||||
return zip.generateAsync({
|
||||
type: "nodebuffer",
|
||||
type: "uint8array",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
compression: "DEFLATE",
|
||||
});
|
||||
|
@ -10,6 +10,9 @@ export default defineConfig({
|
||||
dts(),
|
||||
nodePolyfills({
|
||||
exclude: ["fs"],
|
||||
globals: {
|
||||
Buffer: false,
|
||||
},
|
||||
protocolImports: true,
|
||||
}),
|
||||
],
|
||||
@ -26,7 +29,25 @@ export default defineConfig({
|
||||
lib: {
|
||||
entry: [resolve(__dirname, "src/index.ts")],
|
||||
name: "docx",
|
||||
fileName: "index",
|
||||
fileName: (d) => {
|
||||
if (d === "umd") {
|
||||
return "index.umd.js";
|
||||
}
|
||||
|
||||
if (d === "cjs") {
|
||||
return "index.cjs";
|
||||
}
|
||||
|
||||
if (d === "es") {
|
||||
return "index.js";
|
||||
}
|
||||
|
||||
if (d === "iife") {
|
||||
return "index.iife.js";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
},
|
||||
formats: ["iife", "es", "cjs", "umd"],
|
||||
},
|
||||
outDir: resolve(__dirname, "build"),
|
||||
|
Reference in New Issue
Block a user