So I have been working on updating my project over to the new built-in bundler Alameda.
One of the annoyances for my project was that all the build files and any associated folders/resources were all intermixed with the other project files. The webpack version has a dist folder that was created which made it easy for me to copy the required artifacts over to stage and prod when needed. If you have a CI system setup then perhaps its not much of an issue for you as you can create the script to move stuff once and have it pull as needed.
So I set about trying to get the dist folder setup and working. I spent several hours reading the docs, and doing âau buildâ to finally get the right combination of paths setup so that when doing âau runâ the browser is able to load find and load all the needed scripts and resources.
Two files need to be updated, aurelia.json, and launch.json.
Below are the required updates to each of those files.
(note: no changes were required to index.html)
(note: I use port 8080 versus 9000, you can change that for your needs)
launch.json - change webroot, adding /dist
{
"name": "Chrome Debugger",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080",
"webRoot": "${workspaceRoot}/dist",
"userDataDir": "${workspaceRoot}/.chrome",
"sourceMapPathOverrides": {
"../src/*": "${webRoot}/*"
}
},
aurelia.json - need to update build.targets and platform
"targets": [
{
"id": "web",
"displayName": "Web",
"port": 8080,
"index": "index.html",
"baseDir": "dist",
"output": "dist/scripts",
"baseUrl": "scripts"
}
],
"platform": {
"id": "web",
"displayName": "Web",
"port": 8080,
"index": "index.html",
"baseDir": "dist",
"output": "dist/scripts",
"baseUrl": "dist/scripts"
},
Just to make this complete, I have included below how I copy over any additional resources that are not bundled (aurelia.json). Update based on your project.
"copyFiles": {
"node_modules/font-awesome/fonts/*": "dist/font-awesome/fonts",
"img/*": "dist/img",
"index.html": "dist",
"sw.js": "dist",
"sw.css": "dist",
"rollbar.js": "dist"
},
The only thing I have left to do is figure out how to clear the dist folder, or you could end up with stale resources being moved to other environments. Iâll do an update here when I get that setup.
Here is how to I cleanup the dist folder each time the project is built. (Thanks @huochunpeng)
Install the helper module to delete files
npm i -D del
Create a clean.ts file under the aurelia-project/tasks
import * as del from 'del';
export default function clean() {return del(['dist'])};
update the build.ts file, adding the import and the new clean step
import clean from './clean';
.
.
.
let build = gulp.series(
readProjectConfiguration,
clean,
gulp.parallel(
transpile,
processMarkup,
processJson,
processCSS,
copyFiles
),
writeBundles
);
.
.
.