Skip to content

Commit

Permalink
perf: Pre-compile dependencies to reduce install size/time (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Jan 14, 2022
1 parent 3366cfd commit b214c51
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules

# build output
dist
out

# logs
npm-debug.log
2 changes: 1 addition & 1 deletion babel-test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* eslint-ignore */
module.exports = require('./dist/babel-test')
module.exports = require('./dist/babel').test()
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist')
module.exports = require('./dist/index')
2 changes: 1 addition & 1 deletion macro.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/macro')
module.exports = require('./dist/babel').macro()
31 changes: 18 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
],
"typings": "./index.d.ts",
"scripts": {
"build": "babel src --out-dir dist",
"build": "rm -rf dist && rm -rf out && babel src --out-dir out && yarn build-babel && yarn build-webpack && yarn build-index",
"build-babel": "ncc build out/babel.js -e react -e babel-plugin-macros --target es5 -o dist/babel",
"build-webpack": "ncc build out/webpack.js -e react -e babel-plugin-macros --target es5 -o dist/webpack",
"build-index": "ncc build out/index.js -e react -e babel-plugin-macros --target es5 -o dist/index",
"test": "ava",
"lint": "eslint ./src",
"format": "prettier --write \"./{src,test}/**/*.{js,css}\"",
"prepublishOnly": "rm -rf dist && yarn build && yarn test && yarn lint --quiet"
"prepublishOnly": "yarn build && yarn test && yarn lint --quiet"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -58,44 +61,46 @@
"padding-line-between-statements": 0
}
},
"dependencies": {
"@babel/plugin-syntax-jsx": "7.14.5",
"@babel/types": "7.15.0",
"convert-source-map": "1.7.0",
"loader-utils": "1.2.3",
"source-map": "0.7.3",
"string-hash": "1.1.3",
"stylis": "3.5.4",
"stylis-rule-sheet": "0.0.10"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
"@babel/plugin-syntax-jsx": "7.14.5",
"@babel/plugin-transform-arrow-functions": "7.12.1",
"@babel/plugin-transform-modules-commonjs": "7.12.1",
"@babel/plugin-transform-runtime": "7.12.1",
"@babel/preset-env": "7.12.1",
"@babel/preset-react": "7.12.5",
"@babel/register": "7.12.1",
"@babel/runtime": "7.12.5",
"@babel/types": "7.15.0",
"@vercel/ncc": "0.33.1",
"ava": "1.2.1",
"babel-plugin-macros": "2.8.0",
"convert-source-map": "1.7.0",
"eslint": "7.32.0",
"eslint-config-prettier": "4.0.0",
"husky": "4.3.0",
"loader-utils": "1.2.3",
"prettier": "1.16.4",
"pretty-quick": "3.1.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"semantic-release": "17.2.2"
"semantic-release": "17.2.2",
"source-map": "0.7.3",
"string-hash": "1.1.3",
"stylis": "3.5.4",
"stylis-rule-sheet": "0.0.10"
},
"peerDependencies": {
"react": ">= 16.8.0 || 17.x.x || 18.x.x"
},
"peerDependenciesMeta": {
"@babel/core": {
"optional": true
},
"babel-plugin-macros": {
"optional": true
}
},
"engines": {
Expand Down
8 changes: 8 additions & 0 deletions src/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import {
} from './_utils'
import { STYLE_COMPONENT } from './_constants'

export function macro() {
return require('./macro')
}

export function test() {
return require('./babel-test')
}

export default function({ types: t }) {
const jsxVisitors = {
JSXOpeningElement(path, state) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export {
createStyleRegistry,
useStyleRegistry
} from './stylesheet-registry'

export { default as style } from './style'
2 changes: 1 addition & 1 deletion style.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/style')
module.exports = require('./dist/index').style
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,11 @@
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==

"@vercel/ncc@0.33.1":
version "0.33.1"
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.1.tgz#b240080a3c1ded9446a30955a06a79851bb38f71"
integrity sha512-Mlsps/P0PLZwsCFtSol23FGqT3FhBGb4B1AuGQ52JTAtXhak+b0Fh/4T55r0/SVQPeRiX9pNItOEHwakGPmZYA==

JSONStream@^1.0.4, JSONStream@^1.3.4, JSONStream@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down

0 comments on commit b214c51

Please sign in to comment.