feat(cli): improve dev experience

This commit is contained in:
陈嘉涵
2020-01-15 10:29:03 +08:00
parent 85cf5df279
commit 67e2a2759c
5 changed files with 38 additions and 32 deletions
@@ -10,33 +10,33 @@ import { PACKAGE_ENTRY_FILE, PACKAGE_STYLE_FILE } from '../common/constant';
const PLUGIN_NAME = 'VantCliSitePlugin';
export async function genSiteEntry() {
return new Promise((resolve, reject) => {
genStyleDepsMap()
.then(() => {
genPackageEntry({
outputPath: PACKAGE_ENTRY_FILE
});
genPacakgeStyle({
outputPath: replaceExt(PACKAGE_STYLE_FILE, `.${CSS_LANG}`)
});
genSiteMobileShared();
genSiteDesktopShared();
resolve();
})
.catch(err => {
console.log(err);
reject(err);
});
});
}
export class VantCliSitePlugin {
apply(compiler: Compiler) {
if (process.env.NODE_ENV === 'production') {
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, this.genSiteEntry);
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, genSiteEntry);
} else {
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, this.genSiteEntry);
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, genSiteEntry);
}
}
genSiteEntry() {
return new Promise((resolve, reject) => {
genStyleDepsMap()
.then(() => {
genPackageEntry({
outputPath: PACKAGE_ENTRY_FILE
});
genPacakgeStyle({
outputPath: replaceExt(PACKAGE_STYLE_FILE, `.${CSS_LANG}`)
});
genSiteMobileShared();
genSiteDesktopShared();
resolve();
})
.catch(err => {
console.log(err);
reject(err);
});
});
}
}