Skip to content

Commit

Permalink
chore(loader): [load] fix esbuild loader configuration
Browse files Browse the repository at this point in the history
- https://esbuild.github.io/api/#loader

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Feb 12, 2023
1 parent 89ac841 commit 0a8701e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ too :wink:):
*/

import * as mlly from '@flex-development/mlly'
import pathe from '@flex-development/pathe'
import * as pathe from '@flex-development/pathe'
import * as tscu from '@flex-development/tsconfig-utils'
import * as tutils from '@flex-development/tutils'
import * as esbuild from 'esbuild'
import { fileURLToPath, pathToFileURL } from 'node:url'

Expand Down Expand Up @@ -135,7 +136,7 @@ export const load = async (url, context) => {
/**
* File extension of {@linkcode url}.
*
* @type {string}
* @type {pathe.Ext | tutils.EmptyString}
* @const ext
*/
const ext = pathe.extname(url)
Expand Down Expand Up @@ -167,7 +168,7 @@ export const load = async (url, context) => {
// transpile source code
const { code } = await esbuild.transform(source, {
format: ext === '.cts' ? 'cjs' : 'esm',
loader: /^[cm]/.test(ext) ? 'ts' : ext.slice(1),
loader: ext.slice(/^\.[cm]/.test(ext) ? 2 : 1),
minify: false,
sourcefile: fileURLToPath(url),
sourcemap: 'inline',
Expand Down
7 changes: 4 additions & 3 deletions loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import * as mlly from '@flex-development/mlly'
import pathe from '@flex-development/pathe'
import * as pathe from '@flex-development/pathe'
import * as tscu from '@flex-development/tsconfig-utils'
import * as tutils from '@flex-development/tutils'
import * as esbuild from 'esbuild'
import { fileURLToPath, pathToFileURL } from 'node:url'

Expand Down Expand Up @@ -53,7 +54,7 @@ export const load = async (url, context) => {
/**
* File extension of {@linkcode url}.
*
* @type {string}
* @type {pathe.Ext | tutils.EmptyString}
* @const ext
*/
const ext = pathe.extname(url)
Expand Down Expand Up @@ -85,7 +86,7 @@ export const load = async (url, context) => {
// transpile source code
const { code } = await esbuild.transform(source, {
format: ext === '.cts' ? 'cjs' : 'esm',
loader: /^[cm]/.test(ext) ? 'ts' : ext.slice(1),
loader: ext.slice(/^\.[cm]/.test(ext) ? 2 : 1),
minify: false,
sourcefile: fileURLToPath(url),
sourcemap: 'inline',
Expand Down

0 comments on commit 0a8701e

Please sign in to comment.