2017-10-20 54 views
0

我测试阵营,样板,我试图加载在app/index.html文件中的一些JavaScript文件:阵营样板不会加载在index.html的js文件

<!doctype html> 
<html lang="en"> 
    <head> 
    <!-- The first thing in any HTML file should be the charset --> 
    <meta charset="utf-8"> 
    <!-- Make the page mobile compatible --> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- Allow installing the app to the homescreen --> 
    <link rel="manifest" href="manifest.json"> 
    <meta name="mobile-web-app-capable" content="yes"> 

    <script type="text/javascript" src="myJScriptFile1.js"></script> 
    <script type="text/javascript" src="myJScriptFile2.js"></script> 
    </head> 
    <body> 
    <!-- Display a message if JS has been disabled on the browser. --> 
    <noscript>If you're seeing this message, that means <strong>JavaScript has been disabled on your browser</strong>, please <strong>enable JS</strong> to make this app work.</noscript> 

    <!-- The app hooks into this div --> 
    <div id="app"></div> 
    <!-- A lot of magic happens in this file. HtmlWebpackPlugin automatically includes all assets (e.g. bundle.js, main.css) with the correct HTML tags, which is why they are missing in this HTML file. Don't add any assets here! (Check out webpackconfig.js if you want to know more) --> 
    </body> 
</html> 

这是默认index.html文件。我与npmyarn运行,并在服务器控制台显示我没有错误,但我的浏览器控制台不断告诉我:

Uncaught SyntaxError: Unexpected token < 

就这样,没有更多的错误。这些JavaScript文件工作正常,因为我正在使用它们到另一个基于React的项目中,我也将它们调用到index.html文件中。控制台打印每个文件的错误。如果我追踪错误,它会将我引导至相应的.js文件。

经过近一周搜索网络,我找不到解决方案。就这样,有没有人有如何解决这个问题的想法?

+0

我怀疑你正在请求缺少资源,因此返回一个404-html页面。 – Caramiriel

+0

@ Caramiriel这是一个蹩脚的...但它并不重要,因为myJScriptFile1.js也返回相同的错误。 – assembler

+0

你可以发布你的js代码吗? –

回答

0

嗯,我正在回答自己。我需要在webpack中进行更多的研究。我经历的WebPack实现这一目标:

安装npm i add-asset-html-webpack-plugin -D

然后,在的WebPack配置文件,在插件我说:

new AddAssetHtmlPlugin({ filepath: require.resolve('./some-file') })

,就是这样。