Skip to content

Commit

Permalink
More optimizations for Babel (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
osdevisnot authored Nov 6, 2019
1 parent 77fc648 commit a5d239a
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
dist
/dist
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@

## :sparkles: Features

- :rocket: **zero dependency**
- :tada: **zero config** to bundle your library using only a `package.json`
- :rocket: **zero dependency** build tool.
- :boom: **zero config** typescript support (just rename `*.js` to `*.ts`)
- :star2: **zero config** code transforms using babel macros
- :haircut: **tiny bundles** for all inputs
- :octopus: creates multiple output formats `cjs`, `esm` and `umd`
- :fire: **Modern JS** syntax with class properties, async/await, and generators
- :confetti_ball: Supports **`react`** and **`styled-components`** out of the box.
- :octopus: creates multiple output formats `cjs`, `esm` and `umd`
- :zap: Built in Minification and Gzip Size Tracking
- :cyclone: Built in development server for quick prototyping.
- :confetti_ball: supports `react` and `styled-components` out of the box.
- :snowflake: Carefully picked default to optimize generated code.

### :muscle: Powered By

Expand Down Expand Up @@ -64,17 +65,20 @@ klap init

For more granular control, configure `klap` using these properties in your `package.json`

| option | description | default |
| ------------------- | -------------------------------------- | --------------------- |
| `klap.name` | package name for `umd` bundles | `pkg.name` |
| `klap.port` | port for development server | `1234` |
| `klap.index` | location of index file | `public/index.html` |
| `klap.sourcemap` | sourcemaps for builds | `true` |
| `klap.minify` | minification for builds | `true` |
| `klap.pragma` | pragma for `jsx` and `tsx` compilation | `React.createElement` |
| `klap.pragmaFrag` | pragma for `jsx` and `tsx` fragments | `React.Fragment` |
| `klap.namedExports` | named exports for commonjs modules | `{}` |
| `klap.globals` | gloabal names for umd bundles | `{}` |
| option | description | default |
| ------------------- | ----------------------------------------- | ------------------------------------------ |
| `klap.name` | package name for `umd` bundles | `pkg.name` |
| `klap.port` | port for development server | `1234` |
| `klap.index` | location of index file | `public/index.html` |
| `klap.sourcemap` | sourcemaps for builds | `true` |
| `klap.minify` | minification for builds | `true` |
| `klap.pragma` | pragma for `jsx` and `tsx` compilation | `React.createElement` |
| `klap.pragmaFrag` | pragma for `jsx` and `tsx` fragments | `React.Fragment` |
| `klap.namedExports` | named exports for commonjs modules | `{}` |
| `klap.globals` | global names for umd bundles | `{}` |
| `browserslist` | browserlist compatible compilation target | `>1%, not dead, not ie 11, not op_mini all |

Note: See default [browserlist coverage](https://browserl.ist/?q=%3E1%25%2C+not+dead%2C+not+ie+11%2C+not+op_mini+all)

## :clinking_glasses: License

Expand Down
5 changes: 5 additions & 0 deletions examples/react-component/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/react-component/dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/react-component/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/react-sc-typescript/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions examples/react-sc-typescript/dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions examples/react-sc-typescript/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/react-typescript/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/react-typescript/dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/react-typescript/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/scaffold-typescript/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/scaffold-typescript/dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/scaffold-typescript/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/scaffold/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/scaffold/dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/scaffold/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import presetTs from '@babel/preset-typescript'
import presetReact from '@babel/preset-react'

// babel plugins
import pluginObjectRestSpread from '@babel/plugin-proposal-object-rest-spread'
import pluginAsyncToPromise from 'babel-plugin-transform-async-to-promises'
import pluginClassProperties from '@babel/plugin-proposal-class-properties'
import pluginTransformRegen from '@babel/plugin-transform-regenerator'
Expand All @@ -15,7 +14,7 @@ import pluginMacros from 'babel-plugin-macros'
export const babelConfig = async (command, pkg) => {
const extensions = [...DEFAULT_EXTENSIONS, '.ts', '.tsx', '.json']

const { klap = {} } = pkg
const { klap = {}, browserslist = '>1%, not dead, not ie 11, not op_mini all' } = pkg
const { pragma = 'React.createElement', pragmaFrag = 'React.Fragment' } = klap

const presets = [
Expand All @@ -25,6 +24,7 @@ export const babelConfig = async (command, pkg) => {
loose: true,
useBuiltIns: false,
modules: false,
targets: browserslist,
exclude: ['transform-async-to-generator', 'transform-regenerator'],
},
],
Expand All @@ -33,7 +33,6 @@ export const babelConfig = async (command, pkg) => {
]

const plugins = [
pluginObjectRestSpread,
[pluginAsyncToPromise, { inlineHelpers: true, externalHelpers: true }],
[pluginClassProperties, { loose: true }],
[pluginTransformRegen, { async: false }],
Expand Down
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ npm install
npm run build
npm link

cd examples

for dir in scaffold scaffold-typescript react-component react-typescript react-sc-typescript
do
cd ${dir} && klap build && rm -rf dist/*.map && prettier --write dist/*.js && cd ..
done

cd ~/temp

rm -rf store
Expand Down

0 comments on commit a5d239a

Please sign in to comment.