问题描述
我有一个 Nuxt.js ^2.10.2
应用程序.
I have a Nuxt.js ^2.10.2
App.
当我执行 npm run dev
时,项目构建完美.
When I do npm run dev
, the project builds perfectly.
当我执行 npm run build
然后 npm run start
.一些 JS 文件出现 404 错误.
When I do npm run build
then npm run start
. some JS files are getting 404 error.
ERROR
Request URL: http://localhost:3000/_nuxt/vendors.pages/account.pages/ca.pages/cart.pages/category/_id/
index.pages/checkout/_step/index.pages/.f705ad4d.1-0-128.js
Request Method: GET
Status Code: 404 Not Found
Remote Address: 127.0.0.1:3000
Referrer Policy: no-referrer-when-downgrade
该文件存在于我的项目 dist/_nuxt/vendor.pages/......
中,文件名正确.f705ad4d.1-0-128.js代码>
The file exists on my project in dist/_nuxt/vendor.pages/......
with the correct filename .f705ad4d.1-0-128.js
我的nuxt.config.js
build: {,
filenames: {
app: '[name].' + version + '.js',
chunk: '[name].' + version + '.js',
vendor: '[name].' + version + '.js',
manifest: '[name].' + version + '.js',
},
}
我做错了什么?其他文件正常加载.
What am I doing wrong? As other files are loaded as normal.
推荐答案
找到了答案.以 .
开头的文件不起作用.虽然不知道如何修复它
Found the answer. Files starting with .
dont work. not sure how to fix it though
临时修复:
在我的 nuxt.config.js
中添加了
build: {
filenames: {
app: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js',
chunk: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js',
css: ({ isDev }) => isDev ? '[name].css' : '[contenthash].css',
img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[hash:7].[ext]',
font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[hash:7].[ext]',
video: ({ isDev }) => isDev ? '[path][name].[ext]' : 'videos/[hash:7].[ext]'
}
}
参考:https://nuxtjs.org/api/configuration-build/#filenames
或者只是这样也行
build: {
filenames: {
chunk: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js'
}
}
这篇关于Nuxt.js npm run build 导致一些JS文件找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!