nico-jsx hot reload demo box

This commit is contained in:
afc163 2016-02-11 22:57:53 +08:00
parent 2e839a42fa
commit 55cc3c57e4
2 changed files with 17 additions and 2 deletions

15
nico.js
View File

@ -119,6 +119,21 @@ exports.writers = [
'nico-jsx.StaticWriter',
'nico-jsx.FileWriter'
];
exports.watchFunc = function(e) {
console.log('reload: ' + e.filepath);
var post = e.post;
if (post && post.template === 'code' && post.id) {
var demoNode = $('#' + post.id);
if (demoNode[0]) {
ReactDOM.unmountComponentAtNode(demoNode[0]);
demoNode.next().remove().insertAfter(demoNode);
$(post.html).insertAfter(demoNode.next());
}
} else if (!(/\.js(x?)$/.test(post.filename))) {
location.reload();
}
};
// end settings }}
process.on('uncaughtException', function(err) {

View File

@ -102,7 +102,7 @@
"less-loader": "^2.2.0",
"lesshint-antd": "^1.2.1",
"lodash": "^4.1.0",
"nico-jsx": "~0.7.2",
"nico-jsx": "~0.8.2",
"postcss-loader": "^0.8.0",
"pre-commit": "1.x",
"rc-scroll-anim": "^0.1.7",
@ -123,7 +123,7 @@
},
"scripts": {
"babel": "babel components index.js --out-dir lib",
"start": "npm run clean && nico server",
"start": "npm run clean && nico server --watch",
"clean": "rm -rf _site dist",
"site": "npm run clean && webpack --config webpack.deploy.config.js && webpack --config webpack.antd.config.js && NODE_ENV=PRODUCTION nico build",
"deploy": "rm -rf node_modules && node scripts/install.js && npm run just-deploy",