Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗️build (browser): rewrite build with a browser build #232

Closed
wants to merge 16 commits into from
4 changes: 4 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script type="module">
import { createReport } from './lib/browser.js'
console.log(createReport)
</script>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"url": "git+https://github.com/guigrpa/docx-templates.git"
},
"scripts": {
"compile": "rimraf ./lib && tsc",
"compile": "rimraf ./lib && yarn rollup && tsc",
mathe42 marked this conversation as resolved.
Show resolved Hide resolved
"rollup": "rollup -c",
"prepack": "yarn compile",
"travis": "yarn compile && yarn test",
"jest": "jest --watch --coverage",
Expand Down
52 changes: 52 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable */
import replace from '@rollup/plugin-replace'
import esbuild from 'rollup-plugin-esbuild'
import node from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'

function defineConfig(inFile, outFile, target, isNode, format) {
return {
input: './src/' + inFile,
output: { file: './lib/' + outFile, format, exports: 'named', sourcemap: true },
external: isNode ? ['jszip', 'timm', 'sax', 'vm'] : [],
plugins: [
isNode ? null : node({
preferBuiltins: false
}),
isNode ? null : commonjs(),
replace({
values: {
'process.env.NODE_DEBUG': false,
'process.pid': 42,
'process.nextTick': 'setTimeout',
'process.stdout': 'null',
'process.stderr': 'null',
'process.env.READABLE_STREAM': 'false',
'process.browser': 'true',
'process.env.NODE_ENV': '"production"',
'process': 'undefined'
}
}),
esbuild({
target: target,
minify: true
mathe42 marked this conversation as resolved.
Show resolved Hide resolved
}),
isNode ? null : {
name: 'module-map',
resolveId(id) {
if (id === 'vm') {
return this.resolve('vm-browserify')
}
if (id === 'stream') {
return this.resolve('stream-browserify')
}
}
}
]
}
}

export default [
defineConfig('browser.ts', 'browser.js', 'es2017', false, 'es'),
defineConfig('index.ts', 'index.js', 'es6', true, 'cjs'),
]
3 changes: 3 additions & 0 deletions src/browser-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Buffer } from "buffer/";

(<any>globalThis).Buffer = Buffer;
2 changes: 2 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './browser-polyfill';
jjhbw marked this conversation as resolved.
Show resolved Hide resolved
export * from './index';
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const __IS_BROWSER__: boolean;
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": false,
"emitDeclarationOnly": true,
mathe42 marked this conversation as resolved.
Show resolved Hide resolved
"outDir": "./lib/",
"declaration": true
},
"include": [
"src"
],
"exclude": [
"rollup.config.js"
]
}
Loading