Skip to content

Commit

Permalink
feat: 🎸 init
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Aug 10, 2024
1 parent d76d483 commit 7fee3e8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 192 deletions.
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build-vite:
pnpm --filter vite run build-bundle
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"esbuild": "^0.21.3",
"postcss": "^8.4.40",
"rollup": "^4.13.0",
"rolldown": "latest"
"rolldown": "/home/victor/Documents/rolldown-rs/rolldown/packages/rolldown"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
Expand Down
23 changes: 15 additions & 8 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
import type { RollupCommonJSOptions } from 'dep-types/commonjs'
import type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
import type { TransformOptions } from 'esbuild'
import { loadFallbackPlugin } from 'rolldown/experimental'
import { withTrailingSlash } from '../shared/utils'
import {
DEFAULT_ASSETS_INLINE_LIMIT,
Expand All @@ -29,7 +30,7 @@ import {
import type { InlineConfig, ResolvedConfig } from './config'
import { resolveConfig } from './config'
import { buildReporterPlugin } from './plugins/reporter'
import { buildEsbuildPlugin } from './plugins/esbuild'
// import { buildEsbuildPlugin } from './plugins/esbuild'
import { type TerserOptions, terserPlugin } from './plugins/terser'
import {
arraify,
Expand All @@ -44,10 +45,10 @@ import {
} from './utils'
import { manifestPlugin } from './plugins/manifest'
import type { Logger } from './logger'
import { dataURIPlugin } from './plugins/dataUri'
import { buildImportAnalysisPlugin } from './plugins/importAnalysisBuild'
// import { dataURIPlugin } from './plugins/dataUri'
// import { buildImportAnalysisPlugin } from './plugins/importAnalysisBuild'
import { ssrManifestPlugin } from './ssr/ssrManifestPlugin'
import { loadFallbackPlugin } from './plugins/loadFallback'
// import { loadFallbackPlugin } from './plugins/loadFallback'
import { findNearestPackageData } from './packages'
import type { PackageCache } from './packages'
import {
Expand Down Expand Up @@ -436,17 +437,17 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
const rollupOptionsPlugins = options.rollupOptions.plugins
return {
pre: [
completeSystemWrapPlugin(),
// completeSystemWrapPlugin(),
// ...(usePluginCommonjs ? [commonjsPlugin(options.commonjsOptions)] : []),
dataURIPlugin(),
// dataURIPlugin(),
...((await asyncFlatten(arraify(rollupOptionsPlugins))).filter(
Boolean,
) as Plugin[]),
...(config.isWorker ? [webWorkerPostPlugin()] : []),
],
post: [
buildImportAnalysisPlugin(config),
...(config.esbuild !== false ? [buildEsbuildPlugin(config)] : []),
// buildImportAnalysisPlugin(config),
// ...(config.esbuild !== false ? [buildEsbuildPlugin(config)] : []),
...(options.minify ? [terserPlugin(config)] : []),
...(!config.isWorker
? [
Expand Down Expand Up @@ -545,6 +546,9 @@ export async function build(
onwarn(warning, warn) {
onRollupWarning(warning, warn, config)
},
experimental: {
// enableComposingJsPlugins: true
},
}

/**
Expand Down Expand Up @@ -785,6 +789,9 @@ export async function build(
}
throw e
} finally {
if (bundle) {
await bundle.destroy()
}
// if (bundle) await bundle.close()
}
}
Expand Down
48 changes: 29 additions & 19 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import aliasPlugin, { type ResolverFunction } from '@rollup/plugin-alias'
import type { ObjectHook } from 'rolldown'
import {
globImportPlugin,
modulePreloadPolyfillPlugin,
transformPlugin,
} from 'rolldown/experimental'
import type { PluginHookUtils, ResolvedConfig } from '../config'
import { isDepsOptimizerEnabled } from '../config'
import type { HookHandler, Plugin, PluginWithRequiredHook } from '../plugin'
Expand All @@ -17,15 +22,16 @@ import { assetPlugin } from './asset'
import { clientInjectionsPlugin } from './clientInjections'
import { buildHtmlPlugin, htmlInlineProxyPlugin } from './html'
import { wasmFallbackPlugin, wasmHelperPlugin } from './wasm'
import { modulePreloadPolyfillPlugin } from './modulePreloadPolyfill'
// import { modulePreloadPolyfillPlugin } from './modulePreloadPolyfill'
import { webWorkerPlugin } from './worker'
import { preAliasPlugin } from './preAlias'
import { definePlugin } from './define'
import { workerImportMetaUrlPlugin } from './workerImportMetaUrl'
import { assetImportMetaUrlPlugin } from './assetImportMetaUrl'
import { metadataPlugin } from './metadata'
import { dynamicImportVarsPlugin } from './dynamicImportVars'
import { importGlobPlugin } from './importMetaGlob'
// import { importGlobPlugin } from './importMetaGlob'
// import { glob } from 'fast-glob'

export async function resolvePlugins(
config: ResolvedConfig,
Expand All @@ -44,18 +50,20 @@ export async function resolvePlugins(
(isDepsOptimizerEnabled(config, false) ||
isDepsOptimizerEnabled(config, true))
return [
// transformPlugin(),
depsOptimizerEnabled ? optimizedDepsPlugin(config) : null,
isBuild ? metadataPlugin() : null,
!isWorker ? watchPackageDataPlugin(config.packageCache) : null,
preAliasPlugin(config),
!isBuild ? preAliasPlugin(config) : null,
aliasPlugin({
entries: config.resolve.alias,
customResolver: viteAliasCustomResolver,
}),
...prePlugins,
modulePreload !== false && modulePreload.polyfill
? modulePreloadPolyfillPlugin(config)
: null,
modulePreloadPolyfillPlugin(),
// modulePreload !== false && modulePreload.polyfill
// ? modulePreloadPolyfillPlugin(config)
// : null,
resolvePlugin({
...config.resolve,
root: config.root,
Expand All @@ -76,26 +84,28 @@ export async function resolvePlugins(
htmlInlineProxyPlugin(config),
cssPlugin(config),
config.esbuild !== false ? esbuildPlugin(config) : null,
jsonPlugin(
{
namedExports: true,
...config.json,
},
isBuild,
),
wasmHelperPlugin(config),
// jsonPlugin(
// {
// namedExports: true,
// ...config.json,
// },
// isBuild,
// ),
// wasmHelperPlugin(config),
webWorkerPlugin(config),
assetPlugin(config),
...normalPlugins,
wasmFallbackPlugin(),
// wasmFallbackPlugin(),
definePlugin(config),
cssPostPlugin(config),
isBuild && buildHtmlPlugin(config),
workerImportMetaUrlPlugin(config),
assetImportMetaUrlPlugin(config),
...buildPlugins.pre,
dynamicImportVarsPlugin(config),
importGlobPlugin(config),
// dynamicImportVarsPlugin(),
// importGlobPlugin(config),
globImportPlugin(),
...postPlugins,
...buildPlugins.post,
// internal server-only plugins are always applied after everything else
Expand Down Expand Up @@ -143,9 +153,9 @@ export function getSortedPluginsByHook<K extends keyof Plugin>(
const sortedPlugins: Plugin[] = []
// Use indexes to track and insert the ordered plugins directly in the
// resulting array to avoid creating 3 extra temporary arrays per hook
const pre = 0;
let normal = 0;
// post = 0
const pre = 0
let normal = 0
// post = 0
for (const plugin of plugins) {
const hook = plugin[hookName]
if (hook) {
Expand Down
Loading

0 comments on commit 7fee3e8

Please sign in to comment.