mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
feat(cli): improve dev experience
This commit is contained in:
@@ -4,6 +4,7 @@ import webpack from 'webpack';
|
||||
import WebpackDevServer from 'webpack-dev-server';
|
||||
import { get } from 'lodash';
|
||||
import { getPort } from 'portfinder';
|
||||
import { GREEN } from '../common/constant';
|
||||
import { siteDevConfig } from '../config/webpack.site.dev';
|
||||
import { sitePrdConfig } from '../config/webpack.site.prd';
|
||||
|
||||
@@ -12,8 +13,8 @@ function logServerInfo(port: number) {
|
||||
const network = `http://${address.ip()}:${port}/`;
|
||||
|
||||
console.log('\n Site running at:\n');
|
||||
console.log(` ${chalk.bold('Local')}: ${chalk.cyan.bold(local)} `);
|
||||
console.log(` ${chalk.bold('Network')}: ${chalk.cyan.bold(network)}`);
|
||||
console.log(` ${chalk.bold('Local')}: ${chalk.hex(GREEN)(local)} `);
|
||||
console.log(` ${chalk.bold('Network')}: ${chalk.hex(GREEN)(network)}`);
|
||||
}
|
||||
|
||||
function runDevServer(port: number) {
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user