Skip to content

Commit

Permalink
feat(browser): build a dedicated version for the browser
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This PR change of the internal directory structure of the exported code. The previous code has move from the `dist/` into the `dist/esm` directory (but remender that we do not avice you to do this 🤓)
  • Loading branch information
armandabric committed Nov 10, 2017
1 parent 2357eb7 commit d2d78d7
Show file tree
Hide file tree
Showing 5 changed files with 693 additions and 16 deletions.
Empty file added dist/cjs/.gitkeep
Empty file.
Empty file added dist/esm/.gitkeep
Empty file.
28 changes: 22 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
"name": "react-element-to-jsx-string",
"version": "13.0.0",
"description": "Turn a ReactElement into the corresponding JSX string.",
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"browser": "dist/cjs/index.js",
"scripts": {
"build":
"babel ./src/ --ignore=*.spec.js --source-maps --out-dir ./dist/ && flow-copy-source -v --ignore=*.spec.js src/ dist/",
"lint": "node_modules/.bin/eslint .",
"clean": "npm run esm:clean && npm run cjs:clean",
"prebuild": "npm run clean",
"build": "npm run esm:build && npm run cjs:build",
"esm:build":
"babel ./src/ --ignore=*.spec.js --source-maps --out-dir ./dist/esm && flow-copy-source -v --ignore=*.spec.js src/ dist/esm",
"esm:clean": "rm -rf ./dist/esm/*",
"cjs:build": "rollup --config rollup.config.js",
"cjs:clean": "rm -rf ./dist/cjs/*",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"flow": "flow",
"precommit": "lint-staged",
"prepublish": "npm run build",
"prebuild": "mkdir -p dist && rm -rf ./dist/*",
"prettier:fix":
"prettier --write --single-quote --trailing-comma es5 \"{src/**/*.js,package.json}\"",
"test": "jest && npm run lint && npm run flow",
Expand All @@ -38,6 +45,7 @@
"babel-cli": "6.26.0",
"babel-eslint": "8.0.2",
"babel-jest": "21.2.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-flow": "6.23.0",
"babel-preset-react": "6.24.1",
Expand All @@ -63,7 +71,15 @@
"prettier": "1.8.2",
"react": "16.1.0",
"react-dom": "16.1.0",
"react-test-renderer": "16.1.0"
"react-test-renderer": "16.1.0",
"rollup": "^0.51.3",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.1.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-sourcemaps": "^0.4.2"
},
"peerDependencies": {
"react": "^0.14.8 || ^15.0.1 || ^16.0.0"
Expand Down
49 changes: 49 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import flow from 'rollup-plugin-flow';
import resolve from 'rollup-plugin-node-resolve';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';

export default {
input: 'src/index.js',
output: {
file: 'dist/cjs/bundle.js',
format: 'cjs',
},
sourcemap: true,
plugins: [
babel({
babelrc: false,
exclude: 'node_modules/**', // only transpile our source code
presets: [
[
'es2015',
{
modules: false,
},
],
'stage-2',
'react',
'flow',
],
plugins: ['external-helpers'],
externalHelpers: true,
}),
resolve({
module: true,
jsnext: true,
main: true,
browser: true,
}),
commonjs({
sourceMap: true,
namedExports: {
react: ['isValidElement'],
},
}),
globals(),
builtins(),
flow(),
],
};
Loading

0 comments on commit d2d78d7

Please sign in to comment.