Skip to content

Commit

Permalink
feat(browser): create separate build for browser and nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Mar 5, 2021
1 parent 1b86533 commit cf4aeab
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 59 deletions.
46 changes: 36 additions & 10 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
module.exports = {
presets: [
'@babel/typescript',
[
'@babel/preset-env'
]
module.exports = {
presets: [
'@babel/typescript',
[
'@babel/preset-env',
{
targets: {
node: '14',
},
},
],
plugins: [
'lodash',
'@babel/proposal-class-properties'
]
],
plugins: ['lodash', '@babel/proposal-class-properties'],
env: {
browser: {
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
},
],
],
presets: [
'@babel/typescript',
[
'@babel/preset-env',
{
targets: {
chrome: '58',
ie: '11',
},
},
],
],
},
},
}
32 changes: 15 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "apollo-proxy-cache",
"version": "4.1.0",
"description": "Provides an apollo-link and express (proxy) middleware setup to support a local `@cache` directive",
"main": "dist/index.js",
"main": "dist/node/index.js",
"browser": "dist/browser/index.js",
"typings": "dist/node/index.d.ts",
"repository": "[email protected]:BowlingX/apollo-proxy-cache.git",
"author": "David Heidrich <[email protected]>",
"license": "MIT",
Expand All @@ -14,15 +16,14 @@
"@types/iltorb": "^2.3.2",
"@types/express": "^4.17.11",
"@types/lodash": "^4.14.168",
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/node": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.8",
"@babel/node": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.9",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-transform-flow-strip-types": "^7.2.3",
"@babel/preset-env": "^7.2.3",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-env": "^7.13.9",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
Expand All @@ -42,12 +43,14 @@
"@babel/preset-typescript": "^7.10.4",
"prettier": "^2.2.1",
"eslint-config-prettier": "^6.15.0",
"babel-plugin-lodash": "^3.3.4"
"babel-plugin-lodash": "^3.3.4",
"cross-env": "^7.0.3"
},
"scripts": {
"prepare": "yarn run build:clean && yarn run build:lib && yarn run build:types",
"prepare": "yarn run build:clean && yarn run build:lib && yarn run build:lib:browser && yarn run build:types",
"build:clean": "rimraf dist",
"build:lib": "babel src -d dist --extensions \".ts\"",
"build:lib": "babel src -d dist/node --extensions \".ts\"",
"build:lib:browser": "cross-env BABEL_ENV=browser babel src -d dist/browser --extensions \".ts\"",
"build:types": "tsc --project tsconfig.types.json",
"test": "yarn eslint src && tsc",
"test-server": "babel-node test/index.js",
Expand Down Expand Up @@ -80,11 +83,6 @@
"lodash": "^4.17.21"
},
"engines": {
"node": ">=12"
},
"targets": {
"chrome": "58",
"ie": "11",
"node": "12"
"node": ">=14"
}
}
2 changes: 1 addition & 1 deletion src/utils-browser-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function removeDirectivesFromQuery(
const docClone = cloneDeep(doc)
docClone.definitions.forEach((definition) => {
if ((definition as OperationDefinitionNode).directives) {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;(definition as any).directives = (definition as OperationDefinitionNode).directives?.filter(
(d) => d.name.value !== directive
)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"outDir": "./dist",
"outDir": "./dist/node",
"rootDir": "./src",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"outDir": "dist",
"outDir": "dist/node",
"declaration": true,
"declarationMap": true,
"isolatedModules": false,
Expand Down
54 changes: 25 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


"@babel/cli@^7.2.3":
"@babel/cli@^7.13.0":
version "7.13.0"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.13.0.tgz#48e77614e897615ca299bece587b68a70723ff4c"
integrity sha512-y5AohgeVhU+wO5kU1WGMLdocFj83xCxVjsVFa2ilII8NEwmBZvx7Ambq621FbFIK68loYJ9p43nfoi6es+rzSA==
Expand Down Expand Up @@ -38,7 +38,7 @@
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.13.8.tgz#5b783b9808f15cef71547f1b691f34f8ff6003a6"
integrity sha512-EaI33z19T4qN3xLXsGf48M2cDqa6ei9tPZlfLdb2HC+e/cFtREiRd8hdSqDbwdLB0/+gLwqJmCYASH0z2bUdog==

"@babel/core@^7.2.2":
"@babel/core@^7.13.8":
version "7.13.8"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.13.8.tgz#c191d9c5871788a591d69ea1dc03e5843a3680fb"
integrity sha512-oYapIySGw1zGhEFRd6lzWNLWFX2s5dA/jm+Pw/+59ZdXtjyIuwlXbrId22Md0rgZVop+aVoqow2riXhBLNyuQg==
Expand Down Expand Up @@ -277,7 +277,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/node@^7.5.5":
"@babel/node@^7.13.0":
version "7.13.0"
resolved "https://registry.yarnpkg.com/@babel/node/-/node-7.13.0.tgz#300ea0f4d516a7586c76797404b951c709bfa821"
integrity sha512-WJcD7YMnTs7qFo45lstvAOR7Sa370sydddnF8JNpD5xen3BwMlhHd0XVVDIB0crYIlSav/W/+dVw+D1wJQUZBQ==
Expand Down Expand Up @@ -309,7 +309,7 @@
"@babel/helper-remap-async-to-generator" "^7.13.0"
"@babel/plugin-syntax-async-generators" "^7.8.4"

"@babel/plugin-proposal-class-properties@^7.13.0", "@babel/plugin-proposal-class-properties@^7.5.5":
"@babel/plugin-proposal-class-properties@^7.13.0":
version "7.13.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.13.0.tgz#146376000b94efd001e57a40a88a525afaab9f37"
integrity sha512-KnTDjFNC1g+45ka0myZNvSBFLhNCLN+GeGYLDEA8Oq7MZ6yMgfLoIRh86GRT0FjtJhZw8JyUskP9uvj5pHM9Zg==
Expand Down Expand Up @@ -452,13 +452,6 @@
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"

"@babel/plugin-syntax-flow@^7.12.13":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.12.13.tgz#5df9962503c0a9c918381c929d51d4d6949e7e86"
integrity sha512-J/RYxnlSLXZLVR7wTRsozxKT8qbsx1mNKJzXEEjQ0Kjx1ZACcyHgbanNWNCFtc36IzuWhYWPpvJFFoexoOWFmA==
dependencies:
"@babel/helper-plugin-utils" "^7.12.13"

"@babel/plugin-syntax-json-strings@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz#01ca21b668cd8218c9e640cb6dd88c5412b2c96a"
Expand Down Expand Up @@ -602,14 +595,6 @@
"@babel/helper-builder-binary-assignment-operator-visitor" "^7.12.13"
"@babel/helper-plugin-utils" "^7.12.13"

"@babel/plugin-transform-flow-strip-types@^7.12.13", "@babel/plugin-transform-flow-strip-types@^7.2.3":
version "7.13.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.13.0.tgz#58177a48c209971e8234e99906cb6bd1122addd3"
integrity sha512-EXAGFMJgSX8gxWD7PZtW/P6M+z74jpx3wm/+9pn+c2dOawPpBkUX7BrfyPvo6ZpXbgRIEuwgwDb/MGlKvu2pOg==
dependencies:
"@babel/helper-plugin-utils" "^7.13.0"
"@babel/plugin-syntax-flow" "^7.12.13"

"@babel/plugin-transform-for-of@^7.13.0":
version "7.13.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.13.0.tgz#c799f881a8091ac26b54867a845c3e97d2696062"
Expand Down Expand Up @@ -727,6 +712,18 @@
dependencies:
"@babel/helper-plugin-utils" "^7.12.13"

"@babel/plugin-transform-runtime@^7.13.9":
version "7.13.9"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.13.9.tgz#744d3103338a0d6c90dee0497558150b490cee07"
integrity sha512-XCxkY/wBI6M6Jj2mlWxkmqbKPweRanszWbF3Tyut+hKh+PHcuIH/rSr/7lmmE7C3WW+HSIm2GT+d5jwmheuB0g==
dependencies:
"@babel/helper-module-imports" "^7.12.13"
"@babel/helper-plugin-utils" "^7.13.0"
babel-plugin-polyfill-corejs2 "^0.1.4"
babel-plugin-polyfill-corejs3 "^0.1.3"
babel-plugin-polyfill-regenerator "^0.1.2"
semver "^6.3.0"

"@babel/plugin-transform-shorthand-properties@^7.12.13":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.12.13.tgz#db755732b70c539d504c6390d9ce90fe64aff7ad"
Expand Down Expand Up @@ -795,7 +792,7 @@
core-js "^2.6.5"
regenerator-runtime "^0.13.4"

"@babel/preset-env@^7.2.3":
"@babel/preset-env@^7.13.9":
version "7.13.9"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.13.9.tgz#3ee5f233316b10d066d7f379c6d1e13a96853654"
integrity sha512-mcsHUlh2rIhViqMG823JpscLMesRt3QbMsv1+jhopXEb3W2wXvQ9QoiOlZI9ZbR3XqPtaFpZwEZKYqGJnGMZTQ==
Expand Down Expand Up @@ -869,14 +866,6 @@
core-js-compat "^3.9.0"
semver "^6.3.0"

"@babel/preset-flow@^7.0.0":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/preset-flow/-/preset-flow-7.12.13.tgz#71ee7fe65a95b507ac12bcad65a4ced27d8dfc3e"
integrity sha512-gcEjiwcGHa3bo9idURBp5fmJPcyFPOszPQjztXrOjUE2wWVqc6fIVJPgWPIQksaQ5XZ2HWiRsf2s1fRGVjUtVw==
dependencies:
"@babel/helper-plugin-utils" "^7.12.13"
"@babel/plugin-transform-flow-strip-types" "^7.12.13"

"@babel/preset-modules@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@babel/preset-modules/-/preset-modules-0.1.4.tgz#362f2b68c662842970fdb5e254ffc8fc1c2e415e"
Expand Down Expand Up @@ -2514,6 +2503,13 @@ create-error-class@^3.0.0:
dependencies:
capture-stack-trace "^1.0.0"

cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
dependencies:
cross-spawn "^7.0.1"

cross-spawn@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand All @@ -2523,7 +2519,7 @@ cross-spawn@^5.0.1:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down

0 comments on commit cf4aeab

Please sign in to comment.