Skip to content

Commit

Permalink
fix(cli-plugin-service): remove clean-webpack-plugin and manually del…
Browse files Browse the repository at this point in the history
…ete dest fir
  • Loading branch information
front-end-captain committed Apr 20, 2021
1 parent 8446c56 commit 19c2d57
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 20 deletions.
1 change: 0 additions & 1 deletion packages/@luban/cli-plugin-service/package.json
Expand Up @@ -53,7 +53,6 @@
"address": "^1.1.2",
"body-parser": "^1.19.0",
"chalk": "^2.4.2",
"clean-webpack-plugin": "^3.0.0",
"cli-highlight": "^2.1.1",
"cliui": "^7.0.3",
"copy-webpack-plugin": "^6.0.1",
Expand Down
9 changes: 8 additions & 1 deletion packages/@luban/cli-plugin-service/src/commands/build.ts
Expand Up @@ -6,6 +6,8 @@ import fs from "fs-extra";

import { formatStats, logStatsErrorsAndWarnings } from "../utils/formatStats";
import { delay } from "../utils/serverRender";
import { cleanDest } from "../utils/clean";

import { produceBoilerplate, produceRoutesAndStore } from "../lib/produce";
import { CommandPluginAPI } from "../lib/PluginAPI";
import {
Expand Down Expand Up @@ -63,7 +65,6 @@ class Build {
targetDirShort,
)} directory is ready to be deployed.`,
);
console.log();

resolve();
});
Expand All @@ -84,12 +85,14 @@ class Build {

const targetDirShort = path.relative(this.api.service.context, this.outputDir);

log(formatStats(stats, targetDirShort, this.api));
console.log();
done(
`Server Build complete. The file ${chalk.cyan(
`${targetDirShort}/server.js`,
)} is ready to be deployed.`,
);
console.log();

resolve();
});
Expand Down Expand Up @@ -129,6 +132,10 @@ class Build {
public async start() {
const ctx = this.api.getContext();

info(`clean dest files...`);

await cleanDest(ctx, this.outputDir);

const isLubanDirExists = fs.pathExistsSync(ctx + "src/.luban");
if (!isLubanDirExists) {
await produceBoilerplate(ctx);
Expand Down
8 changes: 7 additions & 1 deletion packages/@luban/cli-plugin-service/src/commands/serve.ts
Expand Up @@ -36,6 +36,7 @@ import {
getTemplate,
generateInjectedTag,
} from "../utils/serverRender";
import { cleanDest } from "../utils/clean";

const DEFAULT_HOST = "0.0.0.0";

Expand Down Expand Up @@ -377,9 +378,14 @@ class Serve {
}

public async start() {
const context = this.pluginApi.getContext();

info(`clean dest files...`);

await cleanDest(context, this.pluginApi.resolve(this.projectConfig.outputDir));

await this.init();

const context = this.pluginApi.getContext();
const isLubanDirExists = pathExistsSync(context + "/src/.luban");

if (!isLubanDirExists) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@luban/cli-plugin-service/src/config/devtool.ts
Expand Up @@ -7,7 +7,7 @@ class Devtool implements ConfigPluginInstance {
const isProduction = process.env.NODE_ENV === "production";

api.chainAllWebpack((webpackConfig) => {
if (isProduction) {
if (!isProduction) {
webpackConfig.devtool("cheap-module-eval-source-map");
} else {
webpackConfig.devtool(projectConfig.productionSourceMap ? "source-map" : false);
Expand Down
6 changes: 0 additions & 6 deletions packages/@luban/cli-plugin-service/src/config/plugin.ts
@@ -1,4 +1,3 @@
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import DefinePlugin from "webpack/lib/DefinePlugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import HtmlWebpackPlugin, { Options as HtmlPluginOptions } from "html-webpack-plugin";
Expand Down Expand Up @@ -176,11 +175,6 @@ class Plugin implements ConfigPluginInstance {
});

api.chainAllWebpack((webpackConfig) => {
webpackConfig
.plugin("clean")
.use(CleanWebpackPlugin, [{ verbose: true }])
.end();

webpackConfig
.plugin("extract-css")
.use(MiniCssExtractPlugin, [extractOptions])
Expand Down
2 changes: 1 addition & 1 deletion packages/@luban/cli-plugin-service/src/lib/produce.ts
Expand Up @@ -37,7 +37,7 @@ async function produceStore(useStore: boolean, context: string) {
}

async function produceEntry(useStore: boolean, context: string) {
info("produce client and server entry files ...");
info("produce entry files ...");

const clientEntryTemplatePath = path.resolve(
__dirname,
Expand Down
9 changes: 9 additions & 0 deletions packages/@luban/cli-plugin-service/src/utils/clean.ts
@@ -0,0 +1,9 @@
import fs from "fs-extra";
import path from "path";

export async function cleanDest(context: string, outputDir: string) {
const _path = path.resolve(context, outputDir);
if (fs.pathExistsSync(_path)) {
await fs.remove(_path);
}
}
10 changes: 1 addition & 9 deletions yarn.lock
Expand Up @@ -3866,7 +3866,7 @@
"@types/webpack-sources" "*"
source-map "^0.6.0"

"@types/webpack@4.41.27", "@types/webpack@^4", "@types/webpack@^4.4.31":
"@types/webpack@4.41.27", "@types/webpack@^4":
version "4.41.27"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.27.tgz#f47da488c8037e7f1b2dbf2714fbbacb61ec0ffc"
integrity sha512-wK/oi5gcHi72VMTbOaQ70VcDxSQ1uX8S2tukBK9ARuGXrYM/+u4ou73roc7trXDNmCxCoerE8zruQqX/wuHszA==
Expand Down Expand Up @@ -6619,14 +6619,6 @@ clean-stack@^2.0.0:
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==

clean-webpack-plugin@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-3.0.0.tgz#a99d8ec34c1c628a4541567aa7b457446460c62b"
integrity sha512-MciirUH5r+cYLGCOL5JX/ZLzOZbVr1ot3Fw+KcvbhUb6PM+yycqd9ZhIlcigQ5gl+XhppNmw3bEFuaaMNyLj3A==
dependencies:
"@types/webpack" "^4.4.31"
del "^4.1.1"

cli-boxes@^2.2.0, cli-boxes@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f"
Expand Down

0 comments on commit 19c2d57

Please sign in to comment.