Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Feature/react transform hmre #27

Merged
merged 6 commits into from
Apr 23, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"development": {
"presets": [
"react-hmre"
]
},
"production": {
"plugins": [
"transform-react-remove-prop-types",
"transform-react-constant-elements",
"transform-react-inline-elements"
]
}
},
"presets": ["es2015", "react", "stage-0"]
}
13 changes: 9 additions & 4 deletions .eslintrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
"browser": true,
"amd": true,
"es6": true,
"mocha": true,
"mocha": true
},
"extends": ["standard", "standard-react", "standard-jsx"],
"parser": "babel-eslint",
"rules": {
"strict": 0,
"comma-dangle": [2, "always-multiline"],
"quotes": "single",
"jsx-quotes": [2, "prefer-double"],
"no-multi-spaces": 0,
"no-underscore-dangle": 0,
"quotes": [2, "single"],
"semi": [2, "always"],
"space-before-function-paren": 0
Copy link
Owner

Choose a reason for hiding this comment

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

Not a fan of spaces between function and the opening paren, so would prefer "never" here.

},
"globals": {
"expect": true,
},
"expect": true
}
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v5
Copy link
Owner

Choose a reason for hiding this comment

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

Don't think this should be committed, probably should be ignored in your local .gitignore.

4 changes: 2 additions & 2 deletions app/components/Application/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import ReactTestUtils from 'react-addons-test-utils';
import Application from '../index.jsx';
import styles from '../style.sass';

describe('Application', function() {
it('displays the component', function() {
describe('Application', function () {
it('displays the component', function () {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please remove these leading spaces before each function so that eslint passes? There are a few more throughout the PR too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that... fixed now through the awesome power of npm run lint:js -- --fix :)

const application = ReactTestUtils.renderIntoDocument(
<Application />
);
Expand Down
4 changes: 2 additions & 2 deletions app/components/Application/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Header from '../Header';
import styles from './style';

export default class Application extends React.Component {
render() {
render () {
return <div className={styles.main}>
<div className={styles.wrap}>
<Header />

<main className={styles.body}>
<p>Seems like creating your own React starter kit is a right of passage. So, here's mine.</p>
<p>Seems like creating your own React starter kit is a rite of passage. So, here's mine.</p>
Copy link
Owner

Choose a reason for hiding this comment

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

Oy. Thanks for catching this ☺️

<p>For more information, see the <a href="https://github.com/bradleyboy/yarsk#yarsk">Readme</a>.</p>
</main>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/components/Header/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import ReactTestUtils from 'react-addons-test-utils';
import Header from '../index.jsx';
import styles from '../style.sass';

describe('Header', function() {
it('displays the title', function() {
describe('Header', function () {
it('displays the title', function () {
const header = ReactTestUtils.renderIntoDocument(
<Header />
);

const title = ReactTestUtils.findRenderedDOMComponentWithClass(header, styles.title);
const dom = ReactDOM.findDOMNode(title);
const dom = ReactDOM.findDOMNode(title);
Copy link
Owner

Choose a reason for hiding this comment

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

Extra space here.


expect(dom.textContent).to.equal('YARSK');
});
Expand Down
17 changes: 6 additions & 11 deletions app/components/Header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';

import SubHeader from './subheader';

/**
* Import locally scoped styles using css-loader
* See style.sass in this directory.
Expand All @@ -11,24 +13,17 @@ import styles from './style';
/**
* Reference an image and get back a URL automatically via webpack.
* webpack takes care of versioning, bundling for production, etc.
*/
*/
import logoURL from './images/react-logo.svg';

export default class Header extends React.Component {
render() {
render () {
return <header className={styles.main}>
<img className={styles.logo} src={logoURL} height="125" />
<img className={styles.logo} src={logoURL} height="125"/>

<div className={styles.wrap}>
<h1 className={styles.title}>YARSK</h1>

<h2 className={styles.tagline}>
(<strong>Y</strong>et{' '}
<strong>A</strong>nother{' '}
<strong>R</strong>eact{' '}
<strong>S</strong>tarter{' '}
<strong>K</strong>it)
</h2>
<SubHeader>Yet Another React Starter Kit</SubHeader>
</div>
</header>;
}
Expand Down
15 changes: 15 additions & 0 deletions app/components/Header/subheader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const React = require('react')

import styles from './style'

const SubHeader = ({children}) => (
<h2 className={styles.tagline}>
{children.split(' ').map((word) => {
const arr = word.split('')
return (<span><strong>{arr.shift()}</strong>{arr.join('')} </span>)
}
)}
</h2>
)

export default SubHeader
5 changes: 4 additions & 1 deletion app/css/base.sass
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
*
box-sizing: border-box

html, body, #app
html, body
height: 100%

body
background: black

a
color: #00D8FF

:global(.app)
height: 100vh
4 changes: 2 additions & 2 deletions conf/karma.ci.conf.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var karmaFactory = require('./make-karma-config.js');

module.exports = function(config) {
module.exports = function (config) {
config.set(karmaFactory({
coverage: true,
coverageReporters: [
{ type: 'text' },
{type: 'text'},
],
}));
};
2 changes: 1 addition & 1 deletion conf/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var karmaFactory = require('./make-karma-config.js');

module.exports = function(config) {
module.exports = function (config) {
config.set(karmaFactory({
notify: true,
}));
Expand Down
2 changes: 1 addition & 1 deletion conf/karma.coverage.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var karmaFactory = require('./make-karma-config.js');

module.exports = function(config) {
module.exports = function (config) {
config.set(karmaFactory({
notify: true,
coverage: true,
Expand Down
8 changes: 4 additions & 4 deletions conf/make-karma-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var webpackConfig = require('./webpack.config.js');

module.exports = function(options) {
module.exports = function (options) {
var karmaConfig = {
frameworks: ['mocha', 'chai'],

Expand All @@ -17,7 +17,7 @@ module.exports = function(options) {
},

webpackMiddleware: {
noInfo: true,
noInfo: true,
},

reporters: ['mocha'],
Expand Down Expand Up @@ -46,8 +46,8 @@ module.exports = function(options) {
karmaConfig.coverageReporter = {
dir: '../coverage',
reporters: options.coverageReporters || [
{ type: 'text' },
{ type: 'html' },
{type: 'text'},
{type: 'html'},
],
};

Expand Down
36 changes: 16 additions & 20 deletions conf/make-webpack-config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

function extractForProduction(loaders) {
return ExtractTextPlugin.extract('style', loaders.substr(loaders.indexOf('!')));
}

module.exports = function(options) {
options.lint = fs.existsSync(__dirname + '/../.eslintrc') && options.lint !== false;
module.exports = function (options) {
options.lint = fs.existsSync(path.resolve(__dirname, '..', '.eslintrc')) && options.lint !== false;

var localIdentName = options.production ? '[hash:base64]' : '[path]-[local]-[hash:base64:5]';
var cssLoaders = 'style!css?localIdentName=' + localIdentName + '!autoprefixer?browsers=last 2 versions';
var cssLoaders = 'style!css?module&localIdentName=' + localIdentName + '!postcss?browsers=last 2 versions';
var scssLoaders = cssLoaders + '!sass';
var sassLoaders = scssLoaders + '?indentedSyntax=sass';
var lessLoaders = cssLoaders + '!less';
Expand All @@ -23,8 +25,6 @@ module.exports = function(options) {
lessLoaders = extractForProduction(lessLoaders);
}

var jsLoaders = ['babel'];

return {
entry: options.production ? './app/index.jsx' : [
'webpack-dev-server/client?http://localhost:8080',
Expand All @@ -48,14 +48,9 @@ module.exports = function(options) {
] : [],
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: jsLoaders,
},
{
test: /\.jsx$/,
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: options.production ? jsLoaders : ['react-hot'].concat(jsLoaders),
loaders: ['babel'],
},
{
test: /\.css$/,
Expand All @@ -75,19 +70,19 @@ module.exports = function(options) {
},
{
test: /\.png$/,
loader: "url?limit=100000&mimetype=image/png",
loader: 'url?limit=100000&mimetype=image/png',
},
{
test: /\.svg$/,
loader: "url?limit=100000&mimetype=image/svg+xml",
loader: 'url?limit=100000&mimetype=image/svg+xml',
},
{
test: /\.gif$/,
loader: "url?limit=100000&mimetype=image/gif",
loader: 'url?limit=100000&mimetype=image/gif',
},
{
test: /\.jpg$/,
loader: "file",
loader: 'file',
},
],
},
Expand All @@ -97,8 +92,8 @@ module.exports = function(options) {
plugins: options.production ? [
// Important to keep React file size down
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("production"),
'process.env': {
'NODE_ENV': JSON.stringify('production'),
},
}),
new webpack.optimize.DedupePlugin(),
Expand All @@ -107,7 +102,7 @@ module.exports = function(options) {
warnings: false,
},
}),
new ExtractTextPlugin("app.[hash].css"),
new ExtractTextPlugin('app.[hash].css'),
new HtmlWebpackPlugin({
template: './conf/tmpl.html',
production: true,
Expand All @@ -117,5 +112,6 @@ module.exports = function(options) {
template: './conf/tmpl.html',
}),
],
postcss: [autoprefixer],
};
};
58 changes: 28 additions & 30 deletions conf/phantomjs-shim.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
(function() {
(function () {
var Ap = Array.prototype;
var slice = Ap.slice;
var Fp = Function.prototype;

var Ap = Array.prototype;
var slice = Ap.slice;
var Fp = Function.prototype;
if (!Fp.bind) {
// PhantomJS doesn't support Function.prototype.bind natively, so
// polyfill it whenever this module is required.
Fp.bind = function (context) {
var func = this;
var args = slice.call(arguments, 1);

if (!Fp.bind) {
// PhantomJS doesn't support Function.prototype.bind natively, so
// polyfill it whenever this module is required.
Fp.bind = function(context) {
var func = this;
var args = slice.call(arguments, 1);
function bound() {
var invokedAsConstructor = func.prototype && (this instanceof func);
return func.apply(
// Ignore the context parameter when invoking the bound function
// as a constructor. Note that this includes not only constructor
// invocations using the new keyword but also calls to base class
// constructors such as BaseClass.call(this, ...) or super(...).
!invokedAsConstructor && context || this,
args.concat(slice.call(arguments))
);
}

function bound() {
var invokedAsConstructor = func.prototype && (this instanceof func);
return func.apply(
// Ignore the context parameter when invoking the bound function
// as a constructor. Note that this includes not only constructor
// invocations using the new keyword but also calls to base class
// constructors such as BaseClass.call(this, ...) or super(...).
!invokedAsConstructor && context || this,
args.concat(slice.call(arguments))
);
}

// The bound function must share the .prototype of the unbound
// function so that any object created by one constructor will count
// as an instance of both constructors.
bound.prototype = func.prototype;

return bound;
};
}
// The bound function must share the .prototype of the unbound
// function so that any object created by one constructor will count
// as an instance of both constructors.
bound.prototype = func.prototype;

return bound;
};
}
})();
Loading