Skip to content

Commit

Permalink
[change] export ES modules by default
Browse files Browse the repository at this point in the history
ES modules are the default package export. Commonjs modules are exported
from 'dist/cjs'. Modern bundlers like webpack can consume ES modules.
The addition of the `sideEffects:false` to the `package.json` helps
webpack tree-shaking modules.
  • Loading branch information
necolas committed May 18, 2018
1 parent 96c3f09 commit c4864f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
"scripts": {
"clean": "del ./packages/*/dist",
"compile": "yarn clean && cd packages/react-native-web && babel src --out-dir dist --ignore \"**/__tests__\"",
"compile:commonjs": "MODULES=commonjs babel src --out-dir dist/cjs --ignore \"**/__tests__\"",
"benchmarks": "cd packages/benchmarks && yarn build",
"benchmarks:release": "cd packages/benchmarks && yarn release",
"website": "cd website && yarn start",
"website:release": "cd website && yarn release",
"flow": "flow",
"fmt": "find packages scripts types website -name '*.js' | grep -v -E '(node_modules|dist|vendor)' | xargs yarn fmt:cmd",
"fmt:cmd": "prettier --write",
"jest": "jest --config ./scripts/jest/config.js",
"jest": "MODULES=commonjs jest --config ./scripts/jest/config.js",
"lint": "yarn lint:check --fix",
"lint:check": "eslint packages scripts website",
"precommit": "lint-staged",
"prerelease": "yarn test && yarn compile",
"prerelease": "yarn test && yarn compile && yarn compile:commonjs",
"release": "node ./scripts/release/publish.js",
"postrelease": "yarn website:release && yarn benchmarks:release",
"test": "yarn flow && yarn lint:check && yarn jest --runInBand"
Expand Down
9 changes: 7 additions & 2 deletions packages/benchmarks/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
options: {
cacheDirectory: false,
presets: babelPreset,
plugins: ['react-native-web', 'styled-jsx/babel']
plugins: ['styled-jsx/babel']
}
}
}
Expand All @@ -43,5 +43,10 @@ module.exports = {
analyzerMode: 'static',
openAnalyzer: false
})
]
],
resolve: {
alias: {
'react-native': 'react-native-web'
}
}
};
4 changes: 3 additions & 1 deletion packages/react-native-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "react-native-web",
"version": "0.6.1",
"description": "React Native for Web",
"main": "dist/index.js",
"module": "dist/index.js",
"main": "dist/cjs/index.js",
"sideEffects": false,
"files": [
"dist",
"jest",
Expand Down
1 change: 1 addition & 0 deletions scripts/babel/preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
'babel-preset-env',
{
loose: true,
modules: process.env.MODULES || false,
exclude: ['transform-es2015-typeof-symbol'],
targets: {
browsers: [
Expand Down

0 comments on commit c4864f5

Please sign in to comment.