11import path from 'node:path'
2- import { build } from 'esbuild'
3- import { rollup } from 'rollup'
2+ import { build as esbuild } from 'esbuild'
3+ import { rollup , type Plugin , type RollupOutput } from 'rollup'
4+ import { build as vite } from 'vite'
45import { expect , test } from 'vitest'
56import Raw from '../src'
67
@@ -16,7 +17,7 @@ test('esbuild', async () => {
1617 console.log(text, text2, text3, text4, bytes1)
1718 `
1819
19- const result = await build ( {
20+ const result = await esbuild ( {
2021 stdin : {
2122 contents,
2223 resolveDir,
@@ -29,34 +30,49 @@ test('esbuild', async () => {
2930 expect ( result . outputFiles [ 0 ] . text ) . matchSnapshot ( )
3031} )
3132
33+ const rollupCode = `
34+ import text from "./ts.ts?raw"
35+ import text2 from "./js.js?raw"
36+ import text3 from "./jsx.jsx?raw"
37+ import text4 from "./with.js" with { type: "text" }
38+ console.log(text, text2, text3, text4)
39+ `
40+ const entryFile = path . resolve ( resolveDir , 'main.js' )
41+ const rollupPlugin : Plugin = {
42+ name : 'entry' ,
43+ resolveId ( id ) {
44+ if ( id === entryFile ) {
45+ return entryFile
46+ }
47+ } ,
48+ load ( id ) {
49+ if ( id === entryFile ) {
50+ return rollupCode
51+ }
52+ } ,
53+ }
54+
3255test ( 'rollup' , async ( ) => {
33- const contents = `
34- import text from "./ts.ts?raw"
35- import text2 from "./js.js?raw"
36- import text3 from "./jsx.jsx?raw"
37- import text4 from "./with.js" with { type: "text" }
38- console.log(text, text2, text3, text4)
39- `
40- const entryFile = path . resolve ( resolveDir , 'main.js' )
4156 const bundle = await rollup ( {
4257 input : [ entryFile ] ,
43- plugins : [
44- Raw . rollup ( ) ,
45- {
46- name : 'entry' ,
47- resolveId ( id ) {
48- if ( id === entryFile ) {
49- return entryFile
50- }
51- } ,
52- load ( id ) {
53- if ( id === entryFile ) {
54- return contents
55- }
56- } ,
57- } ,
58- ] ,
58+ plugins : [ Raw . rollup ( ) , rollupPlugin ] ,
5959 } )
6060 const result = await bundle . generate ( { format : 'esm' } )
6161 expect ( result . output [ 0 ] . code ) . matchSnapshot ( )
6262} )
63+
64+ test ( 'vite' , async ( ) => {
65+ const output = await vite ( {
66+ root : resolveDir ,
67+ plugins : [ Raw . vite ( ) , rollupPlugin ] ,
68+ build : {
69+ rollupOptions : {
70+ input : [ entryFile ] ,
71+ } ,
72+ minify : false ,
73+ write : false ,
74+ } ,
75+ logLevel : 'silent' ,
76+ } )
77+ expect ( ( output as RollupOutput ) . output [ 0 ] . code ) . matchSnapshot ( )
78+ } )
0 commit comments