Nag
Nag

Reputation: 31

Dojo 2 - issue of loading js files

Not able to load js files from local where as CDN path working fine in Dojo 2 application. Once included custom JavaScript files using script tag in index.html. But in browser it shows the error 404 file not found.

Please suggest as i need these for my Dojo 2 application.

This is my how i am using script tag to include

script src="assets/js/jquery.js" type="text/javascript"

Upvotes: 0

Views: 204

Answers (2)

Jonathan Newton
Jonathan Newton

Reputation: 830

Assuming you are using the dojo 2 cli you need to move your assets folder into the root of you application, this is in the dojo 2 build docs:

While most assets will be imported by modules in the src/ directory and therefore handled by the main build pipeline, it is often necessary to serve static assets or include assets in the HTML file itself (e.g., the favicon).

Static assets can be added to an assets/ directory at the project root. At build time, these assets are copied as-is without file hashing to output/{mode}/assets, and can be accessed using the absolute /assets/ path. For example, if users need access to a static terms of service document named terms.pdf, that file would added to assets/terms.pdf and accessed via the URL /assets/terms.pdf.

The build also parses src/index.html for CSS, JavaScript, and image assets, hashing them and including them in the output/{mode}/ directory. For example, it is common for applications to display a favicon in the URL bar. If the favicon is named favicon.ico, it can be added to the src/ directory and included in src/index.html with . The build will then hash the file and copy it to output/{mode}/favicon.[hash].ico.

But another option is to add a new npm command "move-assets": "cp -R ./src/assets ./output/dist/assets" to you package config

"scripts": {
    "start": "dojo build --mode dev --watch memory --serve",
    "build": "dojo build --mode dist && npm run move-assets && npm run move-assets",
    "move-assets": "cp -R ./src/assets ./output/dist/assets"
 }

This will move your assets into the build output folder ./output/dist

Upvotes: 0

Matt Wistrand
Matt Wistrand

Reputation: 96

Currently, the Dojo 2 build does not copy external assets to the build directory, but we are working on a way of specifying such assets in the .dojorc config (index.html is not/will not be scanned for assets). In the meantime, another means of delivering static assets will be required (for example, configuring the assets/ path at the server level).

Upvotes: 1

Related Questions