#Move generated file to `dist`?
1 messages · Page 1 of 1 (latest)
Astro does not currently have a built-in approach to move files to the root of the dist folder during the build process. This issue was discussed in a Github issue (https://github.com/withastro/astro/issues/5245) where a user wanted to move a _redirects file into the dist folder on npx astro build. The issue was resolved, but it required a specific fix for the Cloudflare adapter.
If you want to move a file to the dist folder, you might need to create a custom script as part of your build process. This script would run after astro build and move the desired files to the dist folder.
Here's a basic example of how you might do this with a Node.js script:
const fs = require('fs');
const path = require('path');
// Define the source file and destination
const sourceFile = path.join(__dirname, 'path', 'to', 'your', 'file');
const destinationFolder = path.join(__dirname, 'dist');
// Copy the file
fs.copyFileSync(sourceFile, path.join(destinationFolder, path.basename(sourceFile)));
You would then modify your build script in your package.json to run this script after astro build, like so:
"scripts": {
"build": "astro build && node ./path/to/your/script.js"
}
Please replace 'path', 'to', 'your', 'file' and './path/to/your/script.js' with the actual paths to your file and script.
Remember to run npm run build to build your Astro site as mentioned in the Astro documentation (https://docs.astro.build/en/guides/deploy#building-your-site-locally).