New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Passthrough" loader for select extensions #2272
Comments
Maybe it can be the meaning of |
I think a better fit might be a |
|
Until this gets added (I know you're doing this in spare time so not a complaint!!) I got around this by using a build script instead. I figured it may be useful for other people to see how i did it. It's a small shame to have to use javascript directly for build actions but I can't complain at the speed improvement. My script is: const esbuild = require('esbuild')
const { join } = require('path')
const fs = require('fs')
const naverc = fs
.readFileSync(join(__dirname, '../.naverc'), 'utf8')
.replace('\n', '')
const [, , dir, ...files] = process.argv
const filesToTranspile = []
const filesToCopy = []
files.forEach((file) => {
if (/\.test\.js?$/u.test(file) || /\/test\//u.test(file)) {
// ignore
} else if (/\.js$/u.test(file)) {
filesToTranspile.push(file)
} else {
filesToCopy.push(file)
}
})
;(async () => {
const result = await esbuild.build({
entryPoints: filesToTranspile,
platform: 'node',
format: 'cjs',
outdir: `dist/${dir}`,
target: `node${naverc}`,
logLevel: 'info'
})
await Promise.all(
filesToCopy.map(async (file) => {
const destinationFile = join(__dirname, '../dist', file)
const destinationDir = destinationFile.slice(
0,
destinationFile.lastIndexOf('/')
)
await fs.promises.mkdir(destinationDir, { recursive: true })
await fs.promises.copyFile(file, destinationFile)
})
)
console.log(result)
})() and it's called like: The script filters out my test files + test fixtures (primitively, but it works for me!) and then just separates out the transpile targets from the copy targets. It also leverages my project specific node version (via naverc), which will tell esbuild to automatically transpile the unsupported features that i use. Once esbuild has done it's thing, it will run a copy operation on the rest of the files. The speed is nothing to turn your nose up at:
vs new:
I can't even believe it! |
You are my hero 💙 this works exactly as I expected it would. |
Hi. Thank you for the fantastic package.
I am currently in the process of replacing babel with esbuild in my entire toolchain.
I am currently using babel to transpile every file in my project directories, and in another issue (i have lost it now) I use a command very similar to:
However this does not fulfil my requirement exactly - I have additional file types (like json, etc) so i am required to modify the find command to just include any file blindly:
Now comes my issue, I have a file that is just a text file with the extension
.tpl
(it's a template for lodash) - I read this file in when it is required and consume it.I have a few options that i am in the process of trying, but i believe because of the way i am using esbuild to transpile files, i just need a "passthrough" loader option - one that does absolutely nothing to the file and just sends it directly to the output.
This way i could do
--loader:.tpl=passthrough
and still have my desired result.This is related to my issue in privatenumber/tsx#22.
I am more than happy to (try to) write a plugin for this if you do not believe it to be part of the core package - however i do need to ask if it is still possible to use the esbuild cli with the plugin?
related #1089
The text was updated successfully, but these errors were encountered: