Skip to content

Commit

Permalink
feat: rolldown support (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Mar 25, 2024
1 parent f1180aa commit f6a75d7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"require": "./dist/rollup.js",
"import": "./dist/rollup.mjs"
},
"./rolldown": {
"require": "./dist/rolldown.js",
"import": "./dist/rolldown.mjs"
},
"./esbuild": {
"require": "./dist/esbuild.js",
"import": "./dist/esbuild.mjs"
Expand Down Expand Up @@ -88,6 +92,7 @@
"eslint": "^8.57.0",
"fast-glob": "^3.3.2",
"prettier": "^3.2.5",
"rolldown": "0.10.0-canary-862ce3a-20240325012650",
"rollup": "^4.13.0",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
Expand Down
99 changes: 99 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/rolldown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This entry file is for Rolldown plugin.
*
* @module
*/

import unplugin from './index'

/**
* Rolldown plugin
*
* @example
* ```ts
* // rolldown.config.js
* import Replace from 'unplugin-replace/rolldown'
*
* export default {
* plugins: [Replace()],
* }
* ```
*/
export default unplugin.rolldown
12 changes: 12 additions & 0 deletions tests/__snapshots__/rolldown.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`rolldown 1`] = `
"import { default as process } from "node:process";
// tests/fixtures/main.js
const platform = 'darwin';
console.log('hello "darwin"', platform);
console.log(DEV);
export { platform };"
`;
21 changes: 21 additions & 0 deletions tests/rolldown.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from 'node:path'
import { expect, test } from 'vitest'
import { rolldown } from 'rolldown'
import UnpluginReplace from '../src/rolldown'

test('rolldown', async () => {
const build = await rolldown({
input: path.resolve(__dirname, 'fixtures/main.js'),
external: ['node:process'],
plugins: [
UnpluginReplace({
'process.platform': '"darwin"',
}),
],
})
const { output } = await build.generate({ format: 'es' })
const code = output[0].code
expect(code).toMatchSnapshot()
expect(code).not.contains('process.platform')
expect(code).contains('"darwin"')
})
1 change: 0 additions & 1 deletion tests/rollup.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'node:path'
import { describe, expect, test } from 'vitest'
import { rollupBuild } from '@vue-macros/test-utils'

import UnpluginReplace from '../src/rollup'

describe('rollup', () => {
Expand Down

0 comments on commit f6a75d7

Please sign in to comment.