Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp -- dev #2

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Next Next commit
2.22
opt:暂时移除模板文件改动时,刷新页面功能
mango-csl committed Feb 22, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8cb252bfc8ce71eedc30caa42a9f29610100f8e8
40 changes: 20 additions & 20 deletions server.js
Original file line number Diff line number Diff line change
@@ -50,26 +50,26 @@ new WebpackDevServer(compiler, options).listen(sysConfig.dev.port, sysConfig.dev
}
});

// const viewPath = path.join(__dirname, sysConfig.dev.tplPath);
// rm('-rf', viewPath);
// // // 在源码有更新时,更新模板
// compiler.plugin('emit', function (compilation, cb) {
// // console.log('compilation.assets = ', compilation.assets);
// for (const filename in compilation.assets) {
// if (filename.endsWith('.html')) {
// let filepath = path.resolve(viewPath, filename);
// let dirname = path.dirname(filepath);
// if (!fs.existsSync(dirname)) {
// mkdir('-p', dirname);
// }
// // console.log('compilation.assets[filename].source() = ', compilation.assets[filename].source());
// fs.writeFile(filepath, compilation.assets[filename].source(), (err) => {
// if (err) throw err;
// });
// }
// }
// cb();
// });
const viewPath = path.join(__dirname, sysConfig.dev.tplPath);
rm('-rf', viewPath);
// // 在源码有更新时,更新模板
compiler.plugin('emit', function (compilation, cb) {
// console.log('compilation.assets = ', compilation.assets);
for (const filename in compilation.assets) {
if (filename.endsWith('.html')) {
let filepath = path.resolve(viewPath, filename);
let dirname = path.dirname(filepath);
if (!fs.existsSync(dirname)) {
mkdir('-p', dirname);
}
// console.log('compilation.assets[filename].source() = ', compilation.assets[filename].source());
fs.writeFile(filepath, compilation.assets[filename].source(), (err) => {
if (err) throw err;
});
}
}
cb();
});
//
// // 当页面模板有改变时,强制刷新页面
// compiler.plugin('compilation', function (compilation) {