Skip to content

Commit

Permalink
fix: skip transform in bundle mode
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Apr 28, 2021
1 parent 99c689e commit ad2965c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
types
dist
dist
.temp
2 changes: 1 addition & 1 deletion src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const bundle = async (
bundle: true,
write: false,
sourcemap: true,
outdir: 'dist',
plugins: [
{
name: 'rollup',
Expand Down Expand Up @@ -105,7 +106,6 @@ export const bundle = async (
contents: code,
}
}

return {
contents,
loader,
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export default (options: Options = {}): Plugin => {
},

async transform(code, id) {
if (!filter(id)) {
// In bundle mode transformation is handled by esbuild too
if (!filter(id) || options.experimentalBundling) {
return null
}

Expand Down Expand Up @@ -167,7 +168,12 @@ export default (options: Options = {}): Plugin => {
},

async renderChunk(code) {
if (options.minify || options.minifyWhitespace || options.minifyIdentifiers || options.minifySyntax) {
if (
options.minify ||
options.minifyWhitespace ||
options.minifyIdentifiers ||
options.minifySyntax
) {
const result = await transform(code, {
loader: 'js',
minify: options.minify,
Expand Down
34 changes: 17 additions & 17 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os from 'os'
import path from 'path'
import fs from 'fs'
import { rollup, Plugin as RollupPlugin } from 'rollup'
Expand All @@ -7,7 +6,7 @@ import esbuild, { Options } from '../src'

const readFs = (folderName: string, files: Record<string, string>) => {
mockfs.restore()
const tmpDir = path.join(os.tmpdir(), `esbuild/${folderName}`)
const tmpDir = path.join(__dirname, '.temp', `esbuild/${folderName}`)
Object.keys(files).forEach((file) => {
const absolute = path.join(tmpDir, file)
fs.mkdirSync(path.dirname(absolute), { recursive: true })
Expand Down Expand Up @@ -85,7 +84,7 @@ test('minify whitespace only', async () => {
mockfs({
'./fixture/index.js': `
console.log(1 === 1);
`
`,
})
const output = await build({ minifyWhitespace: true })
expect(output[0].code).toMatchInlineSnapshot(`
Expand All @@ -98,7 +97,7 @@ test('minify syntax only', async () => {
mockfs({
'./fixture/index.js': `
console.log(1 === 1);
`
`,
})
const output = await build({ minifySyntax: true })
expect(output[0].code).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -276,32 +275,33 @@ describe('bundle', () => {
).toMatchInlineSnapshot(`
Array [
Object {
"code": "import { F as Foo } from './Foo-78fc0a48.js';
"code": "// test/.temp/esbuild/bundle-simple/fixture/bar.ts
var bar = \\"bar\\";
// test/.temp/esbuild/bundle-simple/fixture/Foo.jsx
var Foo = /* @__PURE__ */ React.createElement(\\"div\\", null, \\"foo \\", bar);
const A = () => /* @__PURE__ */ React.createElement(Foo, null, \\"A\\");
// test/.temp/esbuild/bundle-simple/fixture/entry-a.jsx
var A = () => /* @__PURE__ */ React.createElement(Foo, null, \\"A\\");
export { A };
",
"path": "entry-a.js",
},
Object {
"code": "import { F as Foo } from './Foo-78fc0a48.js';
"code": "// test/.temp/esbuild/bundle-simple/fixture/bar.ts
var bar = \\"bar\\";
const B = () => /* @__PURE__ */ React.createElement(Foo, null, \\"B\\");
// test/.temp/esbuild/bundle-simple/fixture/Foo.jsx
var Foo = /* @__PURE__ */ React.createElement(\\"div\\", null, \\"foo \\", bar);
// test/.temp/esbuild/bundle-simple/fixture/entry-b.jsx
var B = () => /* @__PURE__ */ React.createElement(Foo, null, \\"B\\");
export { B };
",
"path": "entry-b.js",
},
Object {
"code": "const bar = \\"bar\\";
const Foo = /* @__PURE__ */ React.createElement(\\"div\\", null, \\"foo \\", bar);
export { Foo as F };
",
"path": "Foo-78fc0a48.js",
},
]
`)
})
Expand Down

0 comments on commit ad2965c

Please sign in to comment.