Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Add React 0.14 support
Browse files Browse the repository at this point in the history
  • Loading branch information
insin committed Jul 30, 2015
1 parent 4ab8585 commit f6550db
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions bin/heatpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (args.help || args._.length === 0) {
console.log('Options:')
console.log(" -v, --version print heatpack's version")
console.log(' -p, --port port to run the webpack dev server on [default: 3000]')
console.log(' -f, --force force heatpack to run the given script (disable React.render check)')
console.log(' -f, --force force heatpack to run the given script (disables .render() check)')
process.exit(0)
}

Expand All @@ -43,7 +43,9 @@ var options = {

if (!args.force) {
var code = fs.readFileSync(options.entry).toString()
if (code.indexOf('React.render') === -1) {
if (!/React(DOM)?\.render/.test(code)) {
// We'll alias the given file to a unique module name. If someone creates
// this on npm and the user installs it, they're both trolling ¯\_(ツ)_/¯
options.alias['theydoitonpurposelynn'] = options.entry
options.entry = path.join(__dirname, '../dummy.js')
}
Expand Down
8 changes: 7 additions & 1 deletion dummy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
var React = require('react')
try {
var ReactDOM = require('react-dom')
}
catch (e) {
// pass
}
var Component = require('theydoitonpurposelynn')

function render(Component) {
if (!(Component.type && Component.props)) {
Component = <Component/>
}
React.render(Component, document.querySelector('#app'))
(ReactDOM || React).render(Component, document.querySelector('#app'))
}

render(Component)
Expand Down
12 changes: 9 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function findWorkingDirNodeModules() {
}
}

var workingDirNodeModules = findWorkingDirNodeModules()

/**
* We need to special-case exclusion to allow the heatpack dummy entry module to
* be processed by loaders, as it will be under global node_modules.
Expand Down Expand Up @@ -58,15 +60,19 @@ module.exports = function config(options) {
// If there's a node_modules in scope from where the user ran heatpack, we
// want to pick up React from it first, so prepend it to the list of
// directories to resolve modules from.
root: findWorkingDirNodeModules(),
root: workingDirNodeModules,
extensions: ['', '.js', '.jsx', '.cjsx', '.coffee'],
// Resolve webpack dev server entry modules from heatpack's dependencies
fallback: HEATPACK_MODULES,
// A unique alias will be set up for the module passed by the user if
// we're using dummy.js for rendering.
alias: options.alias
},
resolveLoader: {
// Always resolve loaders from heatpack's own dependencies
root: HEATPACK_MODULES
// We always want to pick up whichever version of React the user has...
root: workingDirNodeModules,
// ...but fall back to heatpack's dependencies for everything else
fallback: HEATPACK_MODULES
},
module: {
loaders: [
Expand Down

0 comments on commit f6550db

Please sign in to comment.