-
Notifications
You must be signed in to change notification settings - Fork 151
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
Esbuild clear output directory #87
Comments
You can call the |
@dhh, Sorry, I'm not clear on what you mean by "outputs are stable"? I thought, that each time I save a js file in this gem or a css file in the cssbundling-rails gem, that the files in the output directory were updated? I find sometimes that i'm getting a lot of leftover old files in the build directory. Also, even though I have the output directory ignored, my assets are failing when being deployed and i'm not seeing the latest JS and CSS. Any suggestions on that one? |
Are tou having problems with the build (app/assets/build) or the output (public/assets) directory? Files in the build directory do not have a digest, so every change overwrites the previous version, and there should be mo left over. In the output directory, files are only placed there when the precompile task is run. This task does not automatically removes old files. That’s intentional. To keep that folder clean there are two extra tasks. “clobber” removes all files in the output. “clean” keeps up to 3 versions besides the current one, so that if anything still needs those (cached assets, server that haven’t been rebooted, lazy imports, etc) they don’t get 404s. So, if you want to keep the output clean, you must do “clean precompile” or “clobber precompile” |
@brenogazzola Well i'm not quite sure. I've just deployed a new version of my app via Capistrano and connected via SSH and ran The output to that was:
But i'm not seeing the latest assets on the site. If you view the site at https://neiltonge.co.uk, if you look at the very very bottom left of the homepage after scrolling all the way down, you'll see a new "Back to top" unstyled link. If the assets were correct then, this link would be styled and somewhere on the right hand side. |
Silly question: did you restart the server? Propshaft caches the manifest file so it takes a restart for it to know there are new files. |
Ah, one more thing: do NOT delete the build directory. It MUST be commited to the repository and must exist in the server before the precompile. Otherwise you get some weird behavior where files are not copied from build to output. |
@brenogazzola We should probably have a check on whether the build directory exists and raise a proper exception if it's not. |
@brenogazzola I didn't restart the server. I am using Sprockets by the way. Eg, I've not manually switched to Propshaft yet. My builds folder was being gitignored. I have readded it now and my styles are now working, HOWEVER, my Javascript has now all died. Any suggestions on how to resolve that? I feel a bit more documentation would be very helpful too. Especially for people like me who are not 100% sure how things all integrate. I do understand docs take time after your comment about this last time @brenogazzola so i realise they will come over time. |
@rctneil Before you adopted this gem, did you precompile without restarting and it worked? I'm checking through Sprockets and in production it uses a cached environment, so it should require a restart for new assets to be picked up. Could you give me more details about what exactly is happening to the javascript? Do you see an error? Is it not being copied to the @dhh Should we add this to jsbundling/cssbundling which are the gems that write to |
@rctneil As for documentation, I'm taking a look at the asset pipeline guide, and thinking of how to update it to better explain the new gems. If you have a list of questions and problems you have/had, that would help with updating it. Some stuff I wouldn't think to add because I'm too used to doing them or having the build system do automatically (like Heroku) |
@brenogazzola Before the gem, I honestly cannot remember. The builds folder looks fine in production and the public assets directory also looks correct. The JS requests are all showing in the Inspector apart from one chunk file which is 404'ing. This appears to be causing none of the JS to actually run. You know the JS is running if the logo at the top left wobbles when you hover over it. In development on my local machine, it all runs fine. It's production where it fails. |
Ah, yes. Common problem. Your JS file is bundled and expects the chunk to be named something like You have to use the digest skip feature. In your bundler config use the following Webpack (this is what I used to use): module.exports = {
output: {
filename: '[name].js',
chunkFilename: '[name]-[contenthash].digested.js',
}
} Esbuild (copied this from #15): require('esbuild').build({
chunkNames: '[name]-[hash].digested',
}).catch(() => process.exit(1)) The important part is that that the files that will be included with |
I'll have a go at this shortly. Thanks for taking a look. I will report back |
@brenogazzola Hmmm, This is weird, I'm converting from the one line script to a config style, to allow me to add the chunkNames option. My config file is:
The line in my package.json file is:
When I run
What could be going on? |
I'm not sure. I did the initial esbuild setup for our monolith, but after that we never touched it again, so I don't have much experience with it. For reference, here's our working config file (minus #!/usr/bin/env node
const path = require('path')
const watch = process.argv.includes('--watch')
const esbuild = require('esbuild')
const config = {
absWorkingDir: path.join(process.cwd(), 'app/javascript'),
entryPoints: ['application.js'],
outdir: path.join(process.cwd(), 'app/assets/builds'),
bundle: true,
minify: true,
sourcemap: true,
target: 'es6',
watch: watch
}
esbuild.build(config).catch(() => process.exit(1)) Try using this one. If it still breaks, remove everything on your |
Hi @brenogazzola Apologies for the delay in getting back to you. I have managed to get this to deploy correctly now. I used your file from above with some minor changes and it's all going swimmingly for now at least! If anything changes I will report back! |
How can I get the output directory to be cleared when recompiling takes place?
The text was updated successfully, but these errors were encountered: