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

Make Farm compatible with most Vite plugins #622

Closed
32 of 45 tasks
wre232114 opened this issue Oct 13, 2023 · 0 comments
Closed
32 of 45 tasks

Make Farm compatible with most Vite plugins #622

wre232114 opened this issue Oct 13, 2023 · 0 comments
Assignees
Labels

Comments

@wre232114
Copy link
Member

wre232114 commented Oct 13, 2023

What problem does this feature solve?

It's hard to build a new ecosystem from scratch, to make Farm production-ready as quick as possible, Farm chooses to be compatible with Vite since 0.13.

For the Future, Farm team will focus on Rust - write faster tools in Rust, instead of re-develop existing JS Plugins, Farm will try to reuse Vite's ecosystem as much as possible.

Because Farm uses a rollup-style plugin system, Farm can be compatible with Vite easily. Currently, Farm has compatible with following hooks, Farm will be compatible with most Vite plugins hook in 1.0.

Plugin Compatibility

Build stage hooks to be supported:

  • config
  • configResolved
  • configureServer
  • apply
  • buildStart
  • resolveId
  • load
  • transform
  • buildEnd
  • handleHotUpdate
  • transformIndexHtml
  • shouldTransformCachedModule
  • moduledParsed

Generate stage hook to be supported:

  • renderChunk
  • argumentChunkHash
  • generateBundle
  • writeBundle
  • renderStart
  • closeBundle

Generate stage hook supported since V0.15

Other hooks are not supported.

API Compatibility

import.meta.hot

  • accept
  • dispose
  • prune
  • data
  • decline
  • invalidate
  • on
  • off
  • send

import.meta.hot supported since 0.15

ViteDevServer

  • config: transformed from Farm's server config.
  • middlewares: fully supported
  • httpServer: fully supported
  • watcher: fully supported
  • ws: fully supported
  • moduleGraph: partial supported.
  • pluginContainer
  • resolvedUrls: does not support
  • transfromRequest: does not support
  • transformIndexHtml: does not support
  • ssrLoadModule: does not support
  • ssrFixStacktrace: not supported. do nothing as Farm does not need it.
  • reloadModule: does not support
  • listen: does not support
  • restart: does not support
  • close: does not support
  • bindCLIShortcuts: does not support

config

following field supported:

pluginContainer

export interface PluginContainer {
  options: InputOptions
  getModuleInfo(id: string): ModuleInfo | null
  buildStart(options: InputOptions): Promise<void>
  resolveId(
    id: string,
    importer?: string,
    options?: {
      attributes?: Record<string, string>
      custom?: CustomPluginOptions
      skip?: Set<Plugin>
      ssr?: boolean
      /**
       * @internal
       */
      scan?: boolean
      isEntry?: boolean
    },
  ): Promise<PartialResolvedId | null>
  transform(
    code: string,
    id: string,
    options?: {
      inMap?: SourceDescription['map']
      ssr?: boolean
    },
  ): Promise<{ code: string; map: SourceMap | { mappings: '' } | null }>
  load(
    id: string,
    options?: {
      ssr?: boolean
    },
  ): Promise<LoadResult | null>
  watchChange(
    id: string,
    change: { event: 'create' | 'update' | 'delete' },
  ): Promise<void>
  close(): Promise<void>
}

moduleGraph

ModuleNode: partially supported

export class ModuleNode {
  /**
   * Public served url path, starts with /
   * The same as url in Farm, cause Farm may not serve module separately
   */
  url: string
  /**
   * Resolved file system path + query
   */
  id: string | null = null
  file: string | null = null
  type: 'js' | 'css'

  // following fields are not supported

  // info?: ModuleInfo
  // meta?: Record<string, any>
  // importers = new Set<ModuleNode>()
  // clientImportedModules = new Set<ModuleNode>()
  // ssrImportedModules = new Set<ModuleNode>()
  // acceptedHmrDeps = new Set<ModuleNode>()
  // acceptedHmrExports: Set<string> | null = null
  // importedBindings: Map<string, Set<string>> | null = null
  // isSelfAccepting?: boolean
  // transformResult: TransformResult | null = null
  // ssrTransformResult: TransformResult | null = null
  // ssrModule: Record<string, any> | null = null
  // ssrError: Error | null = null
  // lastHMRTimestamp = 0
  // lastInvalidationTimestamp = 0

  // get importedModules(): Set<ModuleNode> {
  //  const importedModules = new Set(this.clientImportedModules)
  //  for (const module of this.ssrImportedModules) {
  //    importedModules.add(module)
  //  }
  //  return importedModules
  // }
}

watcher

What does the proposed API look like?

Using Vite plugins in Farm out of box:

import { defineConfig } from '@farmfe/core';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  // using plugins in vitePlugins and everything would work fine
  vitePlugins: [vue()]
});
@wre232114 wre232114 pinned this issue Oct 13, 2023
@wre232114 wre232114 added this to the v1.0.0-beta milestone Oct 13, 2023
@wre232114 wre232114 self-assigned this Oct 13, 2023
@wre232114 wre232114 removed this from the v1.0.0-beta milestone Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant