Skip to content

Commit 1b8c237

Browse files
authored
fix build script issue and also build es module (#5)
1 parent 03c208e commit 1b8c237

5 files changed

Lines changed: 50 additions & 22 deletions

File tree

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ tmp
1212

1313
# build
1414
dist
15+
es
1516
lib

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented here. The format is based
44
on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project
55
adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Changed
10+
11+
- build `es` version of the package as well (see [babel.config.js](./babel.config.js))
12+
13+
### Fixed
14+
15+
- fixed `build` script and `main` field issue, causing usage issues
16+
717
## 2019/03/26 0.6.0
818

919
### Added

babel.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable sort-keys */
2+
// inspired by
3+
// - https://github.com/mui-org/material-ui/blob/b62015a61a4dfef72dfcb79cef917d701d50469f/babel.config.js
4+
let defaultPresets
5+
const environment = process.env.BABEL_ENV || 'umd'
6+
7+
// We release a ES version of the package.
8+
// It's something that matches the latest official supported features of
9+
// JavaScript. Nothing more (stage-1, etc), nothing less (require, etc).
10+
if (environment === 'es') {
11+
defaultPresets = []
12+
} else {
13+
defaultPresets = [
14+
[
15+
'@babel/preset-env',
16+
{
17+
// note: we do not build "esm" (compared with material-ui example)
18+
modules: ['umd'].includes(environment) ? false : 'commonjs',
19+
},
20+
],
21+
]
22+
}
23+
24+
module.exports = {
25+
comments: false,
26+
presets: [...defaultPresets, '@babel/preset-react'],
27+
plugins: [
28+
'@babel/plugin-transform-modules-commonjs',
29+
'@babel/plugin-proposal-class-properties',
30+
'@babel/plugin-proposal-object-rest-spread',
31+
],
32+
}

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
"license": "Apache-2.0",
55
"version": "0.6.0",
66
"description": "Manage a catalog (registry) of react-components easily.",
7-
"main": "dist/index.js",
8-
"module": "lib/index.js",
9-
"sideEffects": false,
10-
"files": [
11-
"dist",
12-
"lib"
13-
],
7+
"main": "lib/index.js",
8+
"module": "es/index.js",
9+
"files": ["dist", "es", "lib"],
1410
"scripts": {
15-
"build": "npm run build-lib && npm run build-umd",
16-
"build-lib": "babel src --ignore */*.test.js,**/*.test.js --out-dir lib",
17-
"build-umd": "webpack --mode=production",
11+
"build": "npm run build-cjs && npm run build-es && npm run build-umd",
12+
"build-cjs": "BABEL_ENV=cjs babel src --ignore */*.test.js,**/*.test.js --out-dir lib",
13+
"build-es": "BABEL_ENV=es babel src --ignore */*.test.js,**/*.test.js --out-dir es",
14+
"build-umd": "BABEL_ENV=umd webpack --mode=production",
1815
"coverage": "jest --coverage",
1916
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
2017
"lint": "eslint src",

0 commit comments

Comments
 (0)