Skip to content

Commit 2437eaf

Browse files
committed
build: use rollup to build esm, cjs, and browser bundles
1 parent 58d6dc4 commit 2437eaf

24 files changed

+3576
-5759
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"@babel/plugin-proposal-object-rest-spread",
77
"@babel/transform-async-to-generator"
88
]
9-
}
9+
}

package-lock.json

Lines changed: 3233 additions & 4661 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@
77
"test:unit:watch": "MOCK_AXIOS=true jest ./tests/unit --watch",
88
"test:integration": "jest ./tests/integration/",
99
"test:integration:watch": "jest ./tests/integration/ --watch",
10-
"build": "npm run build:dist && npm run build:lib",
11-
"build:dist": "webpack --mode production",
12-
"build:lib": "NODE_ENV=production babel src --out-dir lib",
10+
"build": "rm -rf ./dist && rollup -c",
1311
"prepublish": "in-publish && npm run build || not-in-publish",
12+
"prepare": "npm run build",
1413
"lint": "standard ./src",
1514
"semantic-release": "semantic-release",
1615
"server": "node ./tests/integration/mockServer.js",
1716
"server:dev": "nodemon ./tests/integration/mockServer.js"
1817
},
19-
"main": "lib/typeform.js",
20-
"directories": {
21-
"lib": "lib",
22-
"test": "tests"
23-
},
18+
"main": "dist/index.cjs.js",
19+
"browser": "dist/typeform-api.js",
20+
"module": "dist/index.esm.js",
2421
"engines": {
2522
"node": ">=8"
2623
},
@@ -42,6 +39,14 @@
4239
"url": "https://github.com/Typeform/js-api-client/issues"
4340
},
4441
"homepage": "https://github.com/Typeform/js-api-client#readme",
42+
"files": [
43+
"dist/**",
44+
"LICENSE.md",
45+
"package.json",
46+
"package-lock.json",
47+
"README.md",
48+
"yarn.lock"
49+
],
4550
"dependencies": {
4651
"axios": "^0.19.0"
4752
},
@@ -70,10 +75,13 @@
7075
"json-server": "^0.14.0",
7176
"lint-staged": "^7.0.4",
7277
"nodemon": "^1.18.3",
78+
"rollup": "^1.20.0",
79+
"rollup-plugin-commonjs": "^10.0.2",
80+
"rollup-plugin-json": "^4.0.0",
81+
"rollup-plugin-node-resolve": "^5.2.0",
82+
"rollup-plugin-terser": "^5.1.1",
7383
"semantic-release": "^15.13.19",
74-
"standard": "^11.0.1",
75-
"webpack": "^4.20.2",
76-
"webpack-cli": "^3.1.1"
84+
"standard": "^11.0.1"
7785
},
7886
"lint-staged": {
7987
"*.js": [

rollup.config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import commonjs from 'rollup-plugin-commonjs'
2+
import json from 'rollup-plugin-json'
3+
import resolveModule from 'rollup-plugin-node-resolve'
4+
import pkg from './package.json'
5+
import { terser } from 'rollup-plugin-terser'
6+
7+
const onwarn = (warning, rollupWarn) => {
8+
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
9+
rollupWarn(warning)
10+
}
11+
}
12+
13+
const plugins = [
14+
commonjs({
15+
include: ['node_modules/**']
16+
}),
17+
json()
18+
]
19+
20+
export default [{
21+
input: 'src/index.js',
22+
output: [{
23+
file: pkg.main,
24+
format: 'cjs',
25+
exports: 'named'
26+
}, {
27+
file: pkg.module,
28+
format: 'es',
29+
exports: 'named'
30+
}],
31+
onwarn,
32+
plugins: [
33+
resolveModule({
34+
mainFields: ['main', 'module'],
35+
preferBuiltins: true
36+
}),
37+
...plugins
38+
],
39+
external: ['http', 'https', 'url', 'zlib', 'assert', 'stream', 'tty', 'util', 'os']
40+
}, {
41+
input: 'src/index.js',
42+
output: {
43+
file: pkg.browser,
44+
format: 'umd',
45+
name: 'typeformAPI',
46+
exports: 'named'
47+
},
48+
onwarn,
49+
plugins: [
50+
resolveModule({
51+
mainFields: ['browser']
52+
}),
53+
terser(),
54+
...plugins
55+
]
56+
}]

src/forms.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Form(http)
2-
3-
class Form {
1+
export class Forms {
42
constructor (_http) {
53
this._http = _http
64
this._messages = new FormMessages(_http)

src/images.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Images(http)
2-
3-
class Images {
1+
export class Images {
42
constructor (_http) {
53
this._http = _http
64
}

src/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { clientConstructor } from './create-client'
2+
import { Forms } from './forms'
3+
import { Images } from './images'
4+
import { Teams } from './teams'
5+
import { Themes } from './themes'
6+
import { Workspaces } from './workspaces'
7+
import { Responses } from './responses'
8+
import { Webhooks } from './webhooks'
9+
10+
export const createClient = (args = {}) => {
11+
if (!args.token) {
12+
throw new Error('Token is missing')
13+
}
14+
15+
const http = clientConstructor(args)
16+
17+
return {
18+
forms: new Forms(http),
19+
images: new Images(http),
20+
teams: new Teams(http),
21+
themes: new Themes(http),
22+
workspaces: new Workspaces(http),
23+
responses: new Responses(http),
24+
webhooks: new Webhooks(http)
25+
}
26+
}

src/responses.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Responses(http)
2-
3-
class Responses {
1+
export class Responses {
42
constructor (_http) {
53
this._http = _http
64
}

src/teams.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { isMemberPropValid, createMemberPatchQuery } from './utils'
22

3-
export default http => new Teams(http)
4-
5-
class Teams {
3+
export class Teams {
64
constructor (_http) {
75
this._http = _http
86
}

src/themes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { FONTS_AVAILABLE } from './constants'
22

3-
export default http => new Themes(http)
4-
5-
class Themes {
3+
export class Themes {
64
constructor (_http) {
75
this._http = _http
86
}

0 commit comments

Comments
 (0)