Skip to content

Commit

Permalink
wip: integrate core alias plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 11, 2024
1 parent 5d45256 commit 658f0da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
16 changes: 5 additions & 11 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,13 @@ class RolldownEnvironment extends DevEnvironment {

// all plugins are shared like Vite 6 `sharedConfigBuild`.
let plugins = this._plugins!
// TODO: adopt more core plugins (should we filter inside `resolvePlugins`?)
// enable some core plugins
// TODO: adopt more (should we filter inside `resolvePlugins`?)
plugins = plugins.filter(
(p) =>
!(
typeof p.name === 'number' ||
p.name?.startsWith('vite:') ||
p.name === 'alias'
) ||
// enable some core plugins
p.name === 'vite:define',
!(typeof p.name === 'number' || p.name?.startsWith('vite:')) ||
['vite:define'].includes(p.name) ||
['AliasPlugin'].includes(p.constructor.name),
)
plugins = plugins.map((p) => injectEnvironmentToHooks(this as any, p))

Expand All @@ -253,9 +250,6 @@ class RolldownEnvironment extends DevEnvironment {
reactRefresh: this.rolldownDevOptions?.reactRefresh,
}),
reactRefreshPlugin(this.rolldownDevOptions),
rolldownExperimental.aliasPlugin({
entries: this.config.resolve.alias,
}),
...plugins,
],
}
Expand Down
5 changes: 4 additions & 1 deletion playground/rolldown-dev-react/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useState } from 'react'
// @ts-expect-error no type
import virtualTest from 'virtual:test'
// @ts-expect-error no type
import testAlias from 'test-alias'

export function App() {
const [count, setCount] = useState(0)
Expand All @@ -12,7 +14,8 @@ export function App() {
<button onClick={() => setCount((count) => count + 1)}>
Count: {count}
</button>
<pre>[virtual:test] {virtualTest}</pre>
<pre>[virtual] {virtualTest}</pre>
<pre>[alias] {testAlias}</pre>
</div>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions playground/rolldown-dev-react/src/test-alias-dest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'test-alias-dest:ok'
8 changes: 7 additions & 1 deletion playground/rolldown-dev-react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { join } from 'node:path'
import { defineConfig } from 'vite'

export default defineConfig({
Expand All @@ -8,6 +9,11 @@ export default defineConfig({
reactRefresh: true,
},
},
resolve: {
alias: {
'test-alias': join(import.meta.dirname, './src/test-alias-dest.tsx'),
},
},
plugins: [
{
name: 'test',
Expand Down Expand Up @@ -36,7 +42,7 @@ export default defineConfig({
handler(id, _options) {
if (id === '\0virtual:test') {
console.log('[debug:load]', this.environment?.name)
return `export default "virtual-ok, environment.name: ${this.environment.name}"`
return `export default "test:virtual:ok, environment.name: ${this.environment.name}"`
}
},
},
Expand Down

0 comments on commit 658f0da

Please sign in to comment.