Skip to content

Commit

Permalink
feat: use tsx loader, add json support
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jul 1, 2020
1 parent 8a36e9a commit e861e4a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const { getOptions } = require('loader-utils')
/** @type {import('esbuild').Service} */
let service

const exts = ['.js', '.jsx', '.ts', '.tsx']
const getLoader = (ext) => {
if (ext === '.json') {
return 'json'
}
return 'tsx'
}

module.exports = async function (source) {
const done = this.async()
Expand All @@ -20,15 +25,10 @@ module.exports = async function (source) {

try {
const ext = path.extname(this.resourcePath)
if (!exts.includes(ext)) {
return done(
new Error(`[esbuild-loader] Unsupported file extension: ${ext}`)
)
}

const result = await service.transform(source, {
target: options.target || 'es2015',
loader: ext.slice(1),
loader: getLoader(ext),
jsxFactory: options.jsxFactory,
jsxFragment: options.jsxFragment,
sourcemap: options.sourceMap
Expand Down

1 comment on commit e861e4a

@mathew-kurian
Copy link

@mathew-kurian mathew-kurian commented on e861e4a Jul 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@egoist the getLoader function defaults to tsx which is not compatible with generic arrow functions (ref evanw/esbuild#265)

Please sign in to comment.