Skip to content

Commit

Permalink
feat: add charset option (#267) (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
leopiccionia committed Apr 6, 2022
1 parent 875aed8 commit d39fed7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Options = {
minifyWhitespace?: boolean
minifyIdentifiers?: boolean
minifySyntax?: boolean
charset?: CommonOptions['charset']
keepNames?: boolean
legalComments?: CommonOptions['legalComments']
target?: string | string[]
Expand Down Expand Up @@ -180,6 +181,7 @@ export default (options: Options = {}): RollupPlugin => {
sourcemap: sourceMap,
sourcefile: id,
pure: options.pure,
charset: options.charset,
legalComments: options.legalComments,
})

Expand Down
2 changes: 2 additions & 0 deletions src/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Options = {
minifyWhitespace?: boolean
minifyIdentifiers?: boolean
minifySyntax?: boolean
charset?: CommonOptions['charset']
keepNames?: boolean
legalComments?: CommonOptions['legalComments']
target?: CommonOptions['target']
Expand All @@ -40,6 +41,7 @@ export const getRenderChunk = (options: Options): RenderChunkHook =>
minifyWhitespace: options.minifyWhitespace,
minifyIdentifiers: options.minifyIdentifiers,
minifySyntax: options.minifySyntax,
charset: options.charset,
keepNames: options.keepNames,
legalComments: options.legalComments,
sourcemap: options.sourceMap !== false,
Expand Down
17 changes: 17 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ describe('esbuild plugin', () => {
`)
})

test('charset', async () => {
const dir = realFs(getTestName(), {
'./fixture/index.js': `
console.log('π')
`,
})
const output = await build({
dir,
rollupPlugins: [esbuild({ charset: 'utf8' })],
format: 'esm',
})
expect(output[0].code).toMatchInlineSnapshot(`
"console.log(\\"π\\");
"
`)
})

test('keepNames', async () => {
const dir = realFs(getTestName(), {
'./fixture/index.js': `
Expand Down

0 comments on commit d39fed7

Please sign in to comment.