Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[added] Build step for compiling to CommonJS modules #417

Merged
merged 15 commits into from
Jun 16, 2017
Merged
20 changes: 19 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{
"presets": ["es2015", "stage-2", "react"]
"presets": ["react"],
"env": {
"commonjs": {
"plugins": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supposedly the env and non-env configs should merge, but I was seeing the below issue when I tried to consolidate. Any help is appreciated.

Tried this:

{
  "presets": ["react"],
  "plugins": [
      "transform-class-properties", 
      "transform-object-rest-spread"
  ],
  "env": {
    "commonjs": {
      "presets": ["env"]
    },
    "es": {
      "presets": [
        ["env", { "modules": false }]
      ]
    }
  }
}

Got this:
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the old .babelrc to fix v2.0.0. I think we need to use latest instead of stage-2.

Copy link
Collaborator

@diasbruno diasbruno Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest isn't enough for this. 'stage-2` should work.

Copy link
Collaborator

@diasbruno diasbruno Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually after some tests, .babelrc is working as expected, but the main in package.json is pointing to the non-compiled version. Your change to compile from src to lib should fix without to much change (I believe).

"transform-class-properties",
"transform-object-rest-spread"
],
"presets": ["env"]
},
"es": {
"plugins": [
"transform-class-properties",
"transform-object-rest-spread"
],
"presets": [
["env", { "modules": false }]
]
}
}
}
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ engines:
javascript:
ratings:
paths:
- lib/**
- src/**
- "**.js"
exclude_paths:
- "specs/"
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ _book
*.diff
examples/__build__
coverage

## Built folders
es
lib
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lib can't be ignored. You can remove es.

2 changes: 1 addition & 1 deletion examples/basic/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Modal from '../../lib/index';
import Modal from '../../src/index';

const appElement = document.getElementById('example');

Expand Down
2 changes: 0 additions & 2 deletions lib/index.js

This file was deleted.

23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "2.0.0",
"description": "Accessible modal dialog component for React.JS",
"main": "./lib/index.js",
"module": "./es/index.js",
"jsnext:main": "./es/index.js",
"repository": {
"type": "git",
"url": "https://github.com/reactjs/react-modal.git"
Expand All @@ -14,20 +16,26 @@
},
"scripts": {
"start": "./node_modules/.bin/webpack-dev-server --inline --host 127.0.0.1 --content-base examples/",
"test": "cross-env NODE_ENV=test karma start",
"lint": "eslint lib/"
"test": "cross-env BABEL_ENV=commonjs NODE_ENV=test karma start",
"lint": "eslint lib/",
"clean": "rimraf lib es",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
"build": "npm run clean && npm run build:commonjs && npm run build:es"
},
"authors": [
"Ryan Florence"
],
"license": "MIT",
"devDependencies": {
"babel-core": "^6.7.4",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.24.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.5.2",
"babel-preset-react": "^6.24.1",
"codeclimate-test-reporter": "^0.4.0",
"coveralls": "^2.13.1",
"cross-env": "^5.0.1",
Expand Down Expand Up @@ -55,14 +63,13 @@
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"rf-release": "0.4.0",
"rimraf": "^2.5.4",
"rimraf": "^2.6.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rimraf dependency can be removed.

"sinon": "next",
"uglify-js": "2.4.24",
"webpack": "^1.12.14",
"webpack-dev-server": "1.11.0"
},
"dependencies": {
"create-react-class": "^15.5.2",
"element-class": "^0.2.0",
"exenv": "1.2.0",
"lodash.assign": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion specs/Modal.events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import expect from 'expect';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Modal from '../lib/components/Modal';
import Modal from '../src/components/Modal';
import {
moverlay, mcontent,
clickAt, mouseDownAt, mouseUpAt, escKeyDown, tabKeyDown,
Expand Down
4 changes: 2 additions & 2 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import createReactClass from 'create-react-class';
import Modal from '../lib/components/Modal';
import * as ariaAppHider from '../lib/helpers/ariaAppHider';
import Modal from '../src/components/Modal';
import * as ariaAppHider from '../src/helpers/ariaAppHider';
import {
isBodyWithReactModalOpenClass,
contentAttribute,
Expand Down
4 changes: 2 additions & 2 deletions specs/Modal.style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import expect from 'expect';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Modal from '../lib/components/Modal';
import * as ariaAppHider from '../lib/helpers/ariaAppHider';
import Modal from '../src/components/Modal';
import * as ariaAppHider from '../src/helpers/ariaAppHider';
import {
mcontent, moverlay,
renderModal, emptyDOM
Expand Down
2 changes: 1 addition & 1 deletion specs/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Modal from '../lib/components/Modal';
import Modal from '../src/components/Modal';
import TestUtils from 'react-addons-test-utils';

const divStack = [];
Expand Down
2 changes: 1 addition & 1 deletion specs/spec_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ testsContext.keys().forEach((path) => {
}
});

const componentsContext = require.context('../lib', true, /\.js$/);
const componentsContext = require.context('../src', true, /\.js$/);
componentsContext.keys().forEach((path) => {
try {
componentsContext(path);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Modal from './components/Modal';

export default Modal;
4 changes: 2 additions & 2 deletions webpack.dist.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var reactDOMExternal = {
module.exports = {

entry: {
'react-modal': './lib/index.js',
'react-modal.min': './lib/index.js'
'react-modal': './src/index.js',
'react-modal.min': './src/index.js'
},

externals: {
Expand Down
2 changes: 1 addition & 1 deletion webpack.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (process.env.CONTINUOUS_INTEGRATION || process.env.COVERAGE) {
commonConfig.module.postLoaders = commonConfig.module.postLoaders || [];
commonConfig.module.postLoaders.push({
test: /\.js$/,
include: path.resolve('lib'),
include: path.resolve('src'),
loader: 'istanbul-instrumenter'
});
}
Expand Down
Loading