简体   繁体   English

Dojo 2-加载js文件的问题

[英]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. 无法从本地加载js文件,因为CDN路径在Dojo 2应用程序中可以正常工作。 Once included custom JavaScript files using script tag in index.html. 一旦包含使用index.html中的脚本标记的自定义JavaScript文件。 But in browser it shows the error 404 file not found. 但是在浏览器中,它显示未找到错误404文件。

Please suggest as i need these for my Dojo 2 application. 请提出建议,因为我的Dojo 2应用程序需要这些。

This is my how i am using script tag to include 这就是我使用脚本标记的方式

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

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). 当前,Dojo 2构建不会将外部资产复制到构建目录,但是我们正在努力在.dojorc配置中指定此类资产的方式(不会/不会扫描index.html资产)。 In the meantime, another means of delivering static assets will be required (for example, configuring the assets/ path at the server level). 同时,将需要另一种传递静态资产的方式(例如,在服务器级别配置assets/路径)。

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 : 假设您正在使用dojo 2 cli,则需要将资产文件夹移动到应用程序的根目录中,这位于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 (eg, the favicon). 尽管大多数资产将由src /目录中的模块导入并因此由主构建管道处理,但通常有必要提供静态资产或将资产包括在HTML文件本身中(例如,收藏夹图标)。

Static assets can be added to an assets/ directory at the project root. 可以将静态资产添加到项目根目录下的assets /目录。 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. 在构建时,这些资产按原样复制而没有文件散列到输出/ {mode} / assets,并且可以使用绝对/ assets /路径进行访问。 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. 例如,如果用户需要访问名为terms.pdf的静态服务条款文档,则该文件将添加到asset / terms.pdf中并通过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. 该构建还将解析src / index.html中的CSS,JavaScript和图像资产,对其进行哈希处理并将其包括在output / {mode} /目录中。 For example, it is common for applications to display a favicon in the URL bar. 例如,应用程序通常在URL栏中显示一个图标。 If the favicon is named favicon.ico, it can be added to the src/ directory and included in src/index.html with . 如果该图标被命名为favicon.ico,则可以将其添加到src /目录中并通过包含在src / index.html中。 The build will then hash the file and copy it to output/{mode}/favicon.[hash].ico. 然后,构建将对文件进行哈希处理并将其复制到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 但是另一种选择是在包配置中添加新的npm命令"move-assets": "cp -R ./src/assets ./output/dist/assets"

"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 这会将您的资产移至构建输出文件夹./output/dist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM