Webpack 网页包未捕获语法错误:意外标记<;
当我使用webpack捆绑我的js文件时 首先,当我在cmd上使用npm运行命令Webpack 网页包未捕获语法错误:意外标记<;,webpack,webpack-dev-server,Webpack,Webpack Dev Server,当我使用webpack捆绑我的js文件时 首先,当我在cmd上使用npm运行命令webpack时,创建了两个bundle文件,即bundle.js和1.bundle.js。创建2个捆绑包文件是否正常 其次,当我在index.html中使用bundle.js时,它会被加载,1.bundle.js也会被加载到页面上,但是1.bundle.js会被修改成一个带有各种脚本标签的html文件。这也正常吗 第三,它在控制台中显示了一个错误,Uncaugh语法错误:意外的令牌主js文件bundle.js试图从
webpack
时,创建了两个bundle文件,即bundle.js
和1.bundle.js
。创建2个捆绑包文件是否正常
其次,当我在index.html
中使用bundle.js
时,它会被加载,1.bundle.js
也会被加载到页面上,但是1.bundle.js
会被修改成一个带有各种脚本标签的html文件。这也正常吗
第三,它在控制台中显示了一个错误,
Uncaugh语法错误:意外的令牌主js文件bundle.js
试图从以这种方式生成的url请求块:
script.src = __webpack_require__.p + "" + chunkId + ".bundle.js";
其中\uuuu webpack\u require\uuu.p
是webpack公共路径
这意味着块将从相对于文档的路径(/websites/t3/node/
)加载。但由于您的文件位于/websites/t3/iflychat app/require/
中,因此无法正确加载块
所以,解决方案是指定js资产的正确路径:
module.exports = {
...
output: {
path: path.resolve('./dist'),
publicPath: '/websites/t3/iflychat-app/require/',
filename: 'bundle.js'
},
...
}
请提供您的webpack config.addedwebpack.config
文件bundle.js
请求自[site]/websites/t3/iflychat app/require/bundle.js
和[site]/websites/t3/node/1.bundle.js
,因此,该文件找不到,而那些
只是Drupal 404页面。你需要在输出
部分指定公共路径
,并使用值/websites/t3/iflychat app/require/
你是最好的伙伴,你知道我欠你一个比萨饼。现在开始工作了。谢谢你的帮助,伙计。也许你可以把它写在回答里,我会接受的。从现在起,我被困在上面大约5个小时了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 1.0" dir="ltr"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:og="http://ogp.me/ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:sioc="http://rdfs.org/sioc/ns#"
xmlns:sioct="http://rdfs.org/sioc/types#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<head profile="http://www.w3.org/1999/xhtml/vocab">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="http://web.iflychatdev.com:12000/websites/t3/misc/favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="shortlink" href="/websites/t3/node/1" />
<link rel="canonical" href="/websites/t3/node/1" />
<meta name="Generator" content="Drupal 7 (http://drupal.org)" />
<title>iflychat-require-app | T3</title>
<style type="text/css" media="all">
</style>
<style type="text/css" media="all">
</style>
<style type="text/css" media="all">
</style>
<style type="text/css" media="all">
@import
...etc
var path = require('path');
module.exports = {
//our config
context: path.resolve(__dirname, 'require'),
entry: './iflychat-main',
output: {
path: path.resolve('./dist'),
filename: 'bundle.js'
},
resolve: {
modulesDirectories: ['.','./require/libs'],
},
}
script.src = __webpack_require__.p + "" + chunkId + ".bundle.js";
module.exports = {
...
output: {
path: path.resolve('./dist'),
publicPath: '/websites/t3/iflychat-app/require/',
filename: 'bundle.js'
},
...
}