Put docx in a seperate namespace in the browser version rather than the global namespace

This commit is contained in:
Dolan Miu
2019-10-12 22:16:36 +01:00
parent 50911fff57
commit 75cdae1473
2 changed files with 17 additions and 15 deletions

View File

@ -12,18 +12,18 @@
<script> <script>
function generate() { function generate() {
const doc = new Document(); const doc = new docx.Document();
doc.addSection({ doc.addSection({
children: [ children: [
new Paragraph({ new docx.Paragraph({
children: [ children: [
new TextRun("Hello World"), new docx.TextRun("Hello World"),
new TextRun({ new docx.TextRun({
text: "Foo Bar", text: "Foo Bar",
bold: true, bold: true,
}), }),
new TextRun({ new docx.TextRun({
text: "Github is the best", text: "Github is the best",
bold: true, bold: true,
}).tab(), }).tab(),
@ -34,7 +34,7 @@
Packer.toBlob(doc).then((blob) => { docx.Packer.toBlob(doc).then((blob) => {
console.log(blob); console.log(blob);
saveAs(blob, "example.docx"); saveAs(blob, "example.docx");
console.log("Document created successfully"); console.log("Document created successfully");

View File

@ -9,6 +9,7 @@ module.exports = {
path: path.resolve("build"), path: path.resolve("build"),
filename: "index.js", filename: "index.js",
libraryTarget: "umd", libraryTarget: "umd",
library: "docx",
}, },
resolve: { resolve: {
@ -24,15 +25,16 @@ module.exports = {
}, },
// For coverage testing // For coverage testing
...(process.env.NODE_ENV !== "production" ...(process.env.NODE_ENV !== "production"
? [{ ? [
test: /\.(ts)/, {
include: path.resolve("src"), test: /\.(ts)/,
loader: "istanbul-instrumenter-loader", include: path.resolve("src"),
enforce: "post", loader: "istanbul-instrumenter-loader",
exclude: [/node_modules/], enforce: "post",
}] exclude: [/node_modules/],
: [] },
) ]
: []),
], ],
}, },