-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathjsx.js
33 lines (29 loc) · 1.25 KB
/
jsx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const BUILD_MODE = typeof window === 'undefined'
import reactTools from 'react-tools'
import ReactMount from 'react/lib/ReactMount'
import reactHotApi from 'react-hot-api'
import path from 'path'
import pascalCase from 'pascal-case'
let classNameFromFilename = (filename) => {
return pascalCase(path.basename(filename,path.extname(filename)))
}
let reexportHotVersionSnippet = (className) => `
console.log("Hot reloading ${className}!")
import ReactMount from 'react/lib/ReactMount'
import reactHotApi from 'react-hot-api'
if (!window.__jsxHot) window.__jsxHot = {}
if (!__jsxHot.${className}) __jsxHot.${className} = reactHotApi(_ => ReactMount._instancesByReactRootID)
let hotted = __jsxHot.${className}(${className})
export {hotted as default}
`
export let translate = load => {
let snippet = BUILD_MODE ? '' : reexportHotVersionSnippet(classNameFromFilename(load.metadata.pluginArgument)),
output = reactTools.transformWithDetails(load.source + snippet, {es6module: true})
load.source = output.code;
load.metadata.sourceMap = output.sourceMap;
}
export let hotReload = module => {
// Noop here either. This only runs on the updated modules, not on
// the first one, and the react-hot-reloader needs to be injected
// from the very beginning.
}