Adjust asset referenced from css#5452
Conversation
|
esbuild has some customizable hooks for loaders and entrypoints. I was planning on using that to implement the hot-reload and fan-out build system. Deno maintains an api for esbuild here https://github.com/denoland/esbuild_client that we could use
Yes, you can control both of these things with esbuild. Viewing which files esbuild resolves: You can use the const result = await esbuild.build({
entryPoints: ['src/styles/main.css'],
bundle: true,
outdir: 'dist',
metafile: true,
});
// Print a human-readable summary
console.log(await esbuild.analyzeMetafile(result.metafile));
// Or inspect the raw object
for (const [output, info] of Object.entries(result.metafile.outputs)) {
console.log(output, '←', Object.keys(info.inputs));
}This shows you exactly which Controlling the loader: You can explicitly tell esbuild how to treat file extensions with the await esbuild.build({
entryPoints: ['src/app.css'],
bundle: true,
loader: {
'.css': 'css', // default — bundle as CSS
'.module.css': 'local-css', // CSS modules (scoped class names)
'.png': 'file', // copy to outdir, emit URL
'.svg': 'dataurl', // inline as data URI
'.woff2': 'file',
},
outdir: 'dist',
});The key CSS-relevant loaders are Controlling path resolution: If esbuild isn't finding files where you expect, you can tweak resolution with await esbuild.build({
// ...
alias: {
'@styles': './src/styles',
},
nodePaths: ['./shared-css'], // extra directories to search
});You can also write a plugin with an |
Adds an asset collector which finds all assets references from inside css and adds those to the bundle. When we optimize the css, we rewrite the urls to match the bundled paths of the assets
Addresses part of #3325