Skip to content

Commit 09afd97

Browse files
authored
transpile sources in build step (#3214)
- update contribution guide
1 parent 5a72620 commit 09afd97

File tree

9 files changed

+429
-52
lines changed

9 files changed

+429
-52
lines changed

.babelrc

-17
This file was deleted.

.babelrc.esm.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./.babelrc.json",
3+
"plugins": ["@babel/plugin-transform-runtime"]
4+
}

.babelrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": [["@babel/env"]],
3+
"exclude": ["node_modules/**"]
4+
}

CONTRIBUTING.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ preparing a pull request please follow these guidelines:
4848
- Make sure to cover new features or bugs with test cases. Test cases should be as small as possible.
4949
- Make sure to follow the PDF specification. JsPDF currently implements part of the PDF 1.3 specification.
5050
- Make sure all tests are green before committing (`npm run test-local`)
51-
- Use only es5-compatible code in the `src` folder (except for import/export statements). The sources are currently
52-
not babeled. When using newer EcmaScript or Browser APIs make sure the required polyfills are listed in
53-
`src/polyfills.js`.
51+
- You may now (and should!) use modern JavaScript everywhere. The build step will transpile it. Most of the sources
52+
are still in ES5, but all new code should be written in ES6+.
53+
- When using newer EcmaScript or Browser APIs make sure the required polyfills are listed in
54+
`src/polyfills.js`. At the moment, the library must still run in IE11!
5455
- Run `npm run prettier` before committing.
5556
- Don't update the files in `dist` in regular pull requests. These are usually only updated when creating a new release.
5657
- For the commit message, follow these guidelines:

package-lock.json

+400-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"url": "https://github.com/MrRio/jsPDF.git"
2424
},
2525
"dependencies": {
26+
"@babel/runtime": "^7.14.0",
2627
"atob": "^2.1.2",
2728
"btoa": "^1.2.1",
2829
"fflate": "^0.4.8"
@@ -35,15 +36,15 @@
3536
},
3637
"devDependencies": {
3738
"@babel/core": "^7.10.4",
38-
"@babel/plugin-external-helpers": "^7.10.4",
39+
"@babel/plugin-transform-runtime": "^7.14.5",
3940
"@babel/preset-env": "^7.10.4",
41+
"@rollup/plugin-babel": "^5.3.0",
4042
"@rollup/plugin-replace": "^2.3.3",
4143
"@rollup/plugin-typescript": "^8.0.0",
4244
"@types/jasmine": "^3.5.11",
4345
"@types/node": "^14.0.18",
4446
"@typescript-eslint/eslint-plugin": "^3.6.0",
4547
"@typescript-eslint/parser": "^3.6.0",
46-
"babel-plugin-rewire-exports": "^2.2.0",
4748
"chalk": "^4.1.0",
4849
"codeclimate-test-reporter": "^0.5.1",
4950
"core-js": "^3.6.0",
@@ -67,7 +68,7 @@
6768
"karma-jasmine": "3.3.1",
6869
"karma-jasmine-matchers": "4.0.2",
6970
"karma-mocha-reporter": "2.2.5",
70-
"karma-rollup-preprocessor": "^7.0.5",
71+
"karma-rollup-preprocessor": "^7.0.7",
7172
"karma-sauce-launcher": "4.1.5",
7273
"karma-typescript": "^5.0.3",
7374
"karma-verbose-reporter": "0.0.6",
@@ -108,5 +109,9 @@
108109
"lint": "prettier --check \"*.{js,ts,md,css,json}\" \"{spec,examples,src,types}/**/*.{js,ts,md,css,json}\"",
109110
"pregenerate-docs": "node deletedocs.js",
110111
"generate-docs": "jsdoc -c jsdoc.json --readme README.md"
111-
}
112+
},
113+
"browserslist": [
114+
"last 2 versions",
115+
"IE 11"
116+
]
112117
}

rollup.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { terser } from "rollup-plugin-terser";
2+
import { babel } from "@rollup/plugin-babel";
23
import RollupPluginPreprocess from "rollup-plugin-preprocess";
34
import resolve from "rollup-plugin-node-resolve";
45
import commonjs from "rollup-plugin-commonjs";
@@ -67,6 +68,7 @@ const umd = {
6768
commonjs(),
6869
RollupPluginPreprocess({ context: { MODULE_FORMAT: "umd" } }),
6970
replaceVersion(),
71+
babel({ babelHelpers: "bundled", configFile: "./.babelrc.json" }),
7072
licenseBanner()
7173
]
7274
};
@@ -94,6 +96,7 @@ const es = {
9496
resolve(),
9597
RollupPluginPreprocess({ context: { MODULE_FORMAT: "es" } }),
9698
replaceVersion(),
99+
babel({ babelHelpers: "runtime", configFile: "./.babelrc.esm.json" }),
97100
licenseBanner()
98101
]
99102
};

test/deployment/esm/karma.conf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const karmaConfig = require("../../karma.common.conf.js");
22
const resolve = require("rollup-plugin-node-resolve");
3+
const commonjs = require("rollup-plugin-commonjs");
34

45
module.exports = config => {
56
config.set({
@@ -51,7 +52,7 @@ module.exports = config => {
5152
},
5253

5354
rollupPreprocessor: {
54-
plugins: [resolve()],
55+
plugins: [resolve(), commonjs()],
5556
output: {
5657
format: "iife",
5758
name: "jspdf",

test/deployment/typescript/karma.conf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const karmaConfig = require("../../karma.common.conf.js");
22
const typescript = require("@rollup/plugin-typescript");
33
const replace = require("@rollup/plugin-replace");
44
const resolve = require("rollup-plugin-node-resolve");
5+
const commonjs = require("rollup-plugin-commonjs");
56

67
module.exports = config => {
78
config.set({
@@ -46,7 +47,8 @@ module.exports = config => {
4647
delimiters: ["", ""],
4748
'"jspdf"': '"../../../dist/jspdf.es.js"'
4849
}),
49-
resolve()
50+
resolve(),
51+
commonjs()
5052
],
5153
output: {
5254
format: "iife",

0 commit comments

Comments
 (0)