Skip to content

Commit

Permalink
react-tools -> babel <3
Browse files Browse the repository at this point in the history
Swap out the use of `react-tools` for `babel`. The main reason for doing this is the way `babel` polyfills at a library level rather than needing it globally, meaning you won't need anyone to change anything about your environment to use fixed-data-table.

This solve the common `Object.assign` doesn't exist issue.
  • Loading branch information
pieterv committed Apr 10, 2015
1 parent b0aed4b commit 3705d58
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stage": 1,
"plugins": ["./build_helpers/objectAssignTransformer.js"],
"blacklist": ["validation.react"]
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ src
__site__
__site_prerender__
.editorconfig
.babelrc
webpack.config.js
CONTRIBUTING.md
9 changes: 9 additions & 0 deletions build_helpers/buildDist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e
PATH=$(npm bin):$PATH

rm -rf ./dist

NODE_ENV=production
webpack
COMPRESS=1 webpack
8 changes: 6 additions & 2 deletions build_helpers/buildNPMInternals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var glob = require('glob');
var path = require('path');
var fs = require('fs');
var reactTools = require('react-tools');
var babel = require('babel-core');

var internalPath = path.join(__dirname, '../internal');
if (!fs.existsSync(internalPath)) {
Expand All @@ -27,11 +27,15 @@ function replaceRequirePath(match, modulePath) {
return '= require(\'' + path + '\');';
}

var babelConf = JSON.parse(
fs.readFileSync('.babelrc', {encoding: 'utf8'})
);

function processFile(fileName) {
var contents = fs.readFileSync(fileName, {encoding: 'utf8'});
var providesModule = providesModuleRegex.exec(contents);
if (providesModule) {
contents = reactTools.transform(contents, {harmony: true, stripTypes: true});
contents = babel.transform(contents, babelConf).code;
contents = contents.replace(moduleRequireRegex, replaceRequirePath);
contents = contents.replace(findDEVRegex, 'process.env.NODE_ENV !== \'production\'');
fs.writeFileSync(
Expand Down
9 changes: 9 additions & 0 deletions build_helpers/objectAssignTransformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var Transformer = require('babel-core').Transformer;

module.exports = new Transformer('object-assign', {
CallExpression: function(node, parent, scope, file) {
if (this.get('callee').matchesPattern('Object.assign')) {
node.callee = file.addHelper('extends');
}
}
});
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@
},
"devDependencies": {
"autoprefixer": "^5.0.0",
"babel-core": "^5.0.8",
"babel-loader": "^5.0.0",
"bundle-loader": "^0.5.2",
"css-loader": "^0.9.1",
"esprima-fb": "^10001.1.0-dev-harmony-fb",
"extract-text-webpack-plugin": "^0.3.8",
"faker": "^2.1.2",
"file-loader": "^0.8.1",
"glob": "^4.3.5",
"html-loader": "^0.2.3",
"jsx-loader": "^0.12.2",
"less": "^2.2.0",
"less-loader": "^2.0.0",
"marked": "^0.3.2",
"node-jsx": "^0.12.4",
"null-loader": "^0.1.0",
"object-assign": "^2.0.0",
"postcss": "^4.0.2",
"postcss-custom-properties": "3.0.1",
"react": "^0.12.2",
Expand All @@ -36,7 +34,7 @@
"scripts": {
"site-dev-server": "./build_helpers/startSiteDevServer.sh",
"site-build": "./build_helpers/buildStaticSite.sh",
"build-dist": "NODE_ENV=production webpack && NODE_ENV=production COMPRESS=1 webpack",
"build-dist": "./build_helpers/buildDist.sh",
"build-npm": "./build_helpers/buildNPMInternals.sh",
"build-docs": "./build_helpers/buildAPIDocs.sh",
"publish-site": "./build_helpers/publishStaticSite.sh",
Expand Down
3 changes: 0 additions & 3 deletions site/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
var React = require('react');
var IndexPage = require('./IndexPage');

// Polyfill ES6 `Object.assign`.
Object.assign = Object.assign || require('object-assign');

React.render(
<IndexPage
{...window.INITIAL_PROPS}
Expand Down
3 changes: 2 additions & 1 deletion site/webpack-client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = {
},
{
test: /\.js$/,
loader: 'jsx-loader?harmony&stripTypes'
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
Expand Down
3 changes: 2 additions & 1 deletion site/webpack-prerender.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
},
{
test: /\.js$/,
loader: 'jsx-loader?harmony&stripTypes'
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module.exports = {
loaders: [
{
test: /\.js$/,
loader: 'jsx-loader?harmony&stripTypes'
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
Expand Down

0 comments on commit 3705d58

Please sign in to comment.