查看配置文件,我们可以看到以下文件已作为依赖项安装:
{
"name": "text",
"path": "../node_modules/systemjs-plugin-text",
"main": "text"
},
查看systemjs-plugin-text文档,需要以下步骤将文本文件的内容导入变量:
import myText from './mytext.html!text';
所以我创建了一个具有以下内容的文本文件:
hello
...
...
,并尝试像这样导入它:
import myText from '/test.txt!text';
但是,出现以下错误:
Error: hello is not defined
因此,据我了解,该文本插件正尝试将text.txt
的内容解析为javascript吗?
这也可能很重要:我尝试加载的文本文件目前尚未放入vendor-bundle
中。因此,就像加载静态文件一样。
好的,所以我设法使其工作。在aurelia.json
中,我发现了这一点:
"loader": {
"type": "system",
"configTarget": "vendor-bundle.js",
"includeBundleMetadataInConfig": "auto",
"plugins": [
{
"name": "text",
"extensions": [
".html",
".css"
],
"stub": true
}
]
}
}
通过更改"stub": false
,我现在可以加载未放置在任何文件包中的文本文件。
这提出了一个问题,为什么将stub
设置为true
?如果我通过将其设置为false
来破坏任何内容?