简体   繁体   English

找不到Riot.js编译器/ 404标记

[英]Riot.js compiler / 404 tag not found

I'm trying to include riot.js tags into my project so that I can reuse components. 我试图将riot.js标记包含到我的项目中,以便可以重用组件。 The app runs on Node+Express and uses Pug for templating. 该应用程序在Node + Express上运行,并使用Pug进行模板化。

I have a route that renders the following page: 我有一条呈现以下页面的路由:

include includes/header.pug
link(rel="stylesheet" href="/styles/kaljasakot.css" type="text/css")
body(id='bootstrap-override')
    div(class='container-fluid')
        div(class='header')
            img(class='okklogo' src='img/okkimg.jpeg' height='80' width='130')
            h1 Kaljasakot
    kaljasakot
    script(type="riot/tag" src="kaljasakot.tag")
    script(src="https://cdn.jsdelivr.net/riot/2.6/riot+compiler.min.js")
    script riot.mount('kaljasakot')
    include includes/footer.pug
    script(src='/js/kaljasakot.js') 

Ie I'm trying to mount the riot tag kaljasakot in the Pug template. 即,我正在尝试在Pug模板中安装防暴标签kaljasakot However the browser gives a 404 error in the console on page render: 但是,浏览器在页面渲染的控制台中给出了404错误:

GET http://localhost:3001/kaljasakot.tag 404 (Not Found) riot+compiler.min.js:2 GET http:// localhost:3001 / kaljasakot.tag 404(未找到)riot + compiler.min.js:2

I'm a little stumped on where the tag file should be located for the compiler to find it, and I can't find any tips on this from Google. 我对标记文件应位于何处感到困惑,编译器可以找到它,而Google对此没有任何提示。 Has anyone come across this case? 有人遇到过这种情况吗?

The whole project can be found here Github link , if needed. 如果需要,可以在Github链接中找到整个项目。

The tag files are not fetched when the Pug template is compiled but from the browser when the app is running. 编译Pug模板时不会获取标记文件,而在应用程序运行时会从浏览器获取。 Currently you haven't told Express where to find the tag files. 目前您还没有告诉Express在哪里可以找到标记文件。

To fix this problem, you can for example create a folder public/tags , move the tag files in there and use them like script(type="riot/tag" src="tags/kaljasakot.tag") . 要解决此问题,您可以例如创建一个文件夹public/tags ,在其中移动标记文件,并像script(type="riot/tag" src="tags/kaljasakot.tag")一样使用它们。 Express will find the files from there because you have configured the public folder as a source for static files. 快递会从那里找到的文件,因为你已经配置了public文件夹的静态文件的来源。

Now the request won't give 404 anymore, but the tag file won't quite work either. 现在请求不再提供404,但是标记文件也无法正常工作。 Since you are using Pug in the tag files, you need to precompile them before the app can use them. 由于您在标记文件中使用Pug,因此需要先对其进行预编译,然后应用才能使用它们。 If you just drop the kaljasakot.tag to public folder as suggested above, you'll see an error Uncaught SyntaxError: Unexpected token = because Riot doesn't understand the Pug syntax. 如果按照上述建议将kaljasakot.tag放到公用文件夹中,则会看到错误Uncaught SyntaxError: Unexpected token =因为Riot不了解Pug语法。

So you'll probably want to just keep the tag files in the views folder after all and set up a build step where you compile the tags and move them to the public/tags folder. 因此,您可能只想将标记文件保留在views文件夹中,并设置一个构建步骤,在该步骤中编译标记并将它们移至public/tags文件夹。 See Riot's documentation on server compilation and gulp-riot for example. 例如,请参阅Riot关于服务器编译gulp-riot 的文档

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

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