Skip to content

Commit

Permalink
chore: prepare write in writeResourcesToDisk
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Dec 10, 2024
1 parent 3f589d1 commit 7788db0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/vue3/farm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import path from "path";
const logger = new Logger({});
const compressionMiddleware = () => {
return {
name: "compression",
name: "compression,
configureServer(server) {
// console.log("server", server.middlewares);
const _printUrls = server.printUrls.bind(server);
Expand Down Expand Up @@ -88,7 +88,7 @@ export default defineConfig({
// Inspector({
// enabled: true,
// }),
// compressionMiddleware(),
compressionMiddleware(),
myCustomPlugin(),
// createHtmlPlugin({
// minify: true,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export async function resolveConfig(
defaultNodeEnv: CompilationMode = 'development',
isPreview = false
): Promise<ResolvedUserConfig> {
// TODO mode 这块还是不对 要区分 mode 和 build 还是 dev 环境
const compileMode = defaultMode;

const mode = inlineOptions.mode || defaultMode;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/plugin/js/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const RESERVED_OBJECT_PROPERTIES: string[] = [
'then',
'length',
'constructor',
'prototype'
'prototype',
'stack'
];

export const EXTERNAL_KEYS: string[] = [
Expand Down
20 changes: 7 additions & 13 deletions packages/core/src/plugin/js/farm-to-vite-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WatchOptions } from 'chokidar';
import type { UserConfig as ViteUserConfig } from 'vite';
import type { UserConfig } from '../../config/types.js';
import { Logger } from '../../index.js';
Expand Down Expand Up @@ -350,17 +351,6 @@ export function viteConfigToFarmConfig(
if (!farmConfig.compilation.resolve.alias) {
farmConfig.compilation.resolve.alias = [];
}

const farmRegexPrefix = '$__farm_regex:';

// for (const { find, replacement } of config.resolve.alias) {
// if (find instanceof RegExp) {
// const key = farmRegexPrefix + find.source;
// farmConfig.compilation.resolve.alias[key] = replacement;
// } else {
// farmConfig.compilation.resolve.alias[find] = replacement;
// }
// }
}
}

Expand Down Expand Up @@ -388,8 +378,9 @@ export function viteConfigToFarmConfig(
: {})
};
}
// TODO think about vite has two watch options `server.watch` | `build.watch` only build watch
// farmConfig.watch = config.server.watch;
if (config.mode === 'development') {
farmConfig.watch = config.server.watch;
}
}

if (typeof config.server.host === 'string') {
Expand All @@ -406,6 +397,9 @@ export function viteConfigToFarmConfig(
}

if (config.build) {
if (config.mode === 'production') {
farmConfig.watch = config.build.watch as WatchOptions;
}
farmConfig.compilation.output ??= {};
farmConfig.compilation.output.path = config.build.outDir;

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class Server extends httpServer {
*/
constructor(readonly inlineConfig: FarmCliOptions & UserConfig) {
super();
this.logger = new Logger();
}

/**
Expand Down

0 comments on commit 7788db0

Please sign in to comment.