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 all 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": [2, "never"]
},
"globals": {
"expect": true,
},
"expect": true
}
}
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
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
2 changes: 1 addition & 1 deletion conf/karma.ci.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(config) {
config.set(karmaFactory({
coverage: true,
coverageReporters: [
{ type: 'text' },
{type: 'text'},
],
}));
};
6 changes: 3 additions & 3 deletions conf/make-karma-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 15 additions & 19 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;
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],
};
};
56 changes: 27 additions & 29 deletions conf/phantomjs-shim.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
(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;
};
}
})();
14 changes: 4 additions & 10 deletions conf/tmpl.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Yet Another React Starter Kit</title>
{% if (o.htmlWebpackPlugin.options.production) { %}
<link rel="stylesheet" href="app.{%=o.webpack.hash%}.css" media="all">
{% } %}
</head>
<body>
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, does this still build the production HTML correctly with CSS and JS included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Magically, it does :)

<div id="app"></div>

{% for (var chunk in o.htmlWebpackPlugin.files.chunks) { %}
<script src="{%=o.htmlWebpackPlugin.files.chunks[chunk].entry %}"></script>
{% } %}
<div class="app" id="app"></div>
</body>
</html>
Loading