diff --git a/package.json b/package.json index 70d7d3b17f..d311efd45b 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "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", @@ -12,11 +13,11 @@ "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" diff --git a/packages/benchmarks/webpack.config.js b/packages/benchmarks/webpack.config.js index 72a77520ce..da2ec65881 100644 --- a/packages/benchmarks/webpack.config.js +++ b/packages/benchmarks/webpack.config.js @@ -32,7 +32,7 @@ module.exports = { options: { cacheDirectory: false, presets: babelPreset, - plugins: ['react-native-web', 'styled-jsx/babel'] + plugins: ['styled-jsx/babel'] } } } @@ -43,5 +43,10 @@ module.exports = { analyzerMode: 'static', openAnalyzer: false }) - ] + ], + resolve: { + alias: { + 'react-native': 'react-native-web' + } + } }; diff --git a/packages/react-native-web/package.json b/packages/react-native-web/package.json index cb1699c19c..5b0b4afac9 100644 --- a/packages/react-native-web/package.json +++ b/packages/react-native-web/package.json @@ -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", diff --git a/scripts/babel/preset.js b/scripts/babel/preset.js index 4caedff0de..05527470b3 100644 --- a/scripts/babel/preset.js +++ b/scripts/babel/preset.js @@ -4,6 +4,7 @@ module.exports = { 'babel-preset-env', { loose: true, + modules: process.env.MODULES || false, exclude: ['transform-es2015-typeof-symbol'], targets: { browsers: [