Skip to content

Commit

Permalink
Properly support window.printJS and module print
Browse files Browse the repository at this point in the history
Expose `printJS` function on the window object (if window exists) (see `/src/index.js`)

Build package via Webpack as a UMD library and purposefully rename
`print` to avoid conflicts.
Update Typescript typings file to reflect this.

Good resources:
http://siawyoung.com/coding/javascript/exporting-es6-modules-as-single-scripts-with-webpack.html
https://webpack.js.org/guides/author-libraries/
https://stackoverflow.com/questions/40294870/module-exports-vs-export-default-in-node-js-and-es6/40295288#40295288
  • Loading branch information
Sam Tsai committed Sep 21, 2018
1 parent 251dea3 commit 3f6c576
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ yarn add print-js
When installing via npm or yarn, import the library into your project:

```
import printJS from 'print-js'
import print from 'print-js'
```

## Documentation
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'print-js/dist/print';

declare type PrintTypes = 'pdf' | 'html' | 'image' | 'json';

export interface Configuration {
Expand Down Expand Up @@ -32,6 +30,6 @@ export interface Configuration {
scanStyles?: boolean;
}

declare var printJS: (params: string | Configuration) => void;
declare var print: (params: string | Configuration) => void;

export default printJS;
export default print;
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if (typeof window !== 'undefined') {
window.printJS = printJS
}

module.exports = printJS
export default printJS
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
'./src/index.js'
],
output: {
library: 'printJS',
library: 'print',
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist'),
filename: 'print.js',
Expand Down

0 comments on commit 3f6c576

Please sign in to comment.