[英]Static files are missing in VueJS application
My first VueJS application structure is as simple as: 我的第一个VueJS应用程序结构很简单:
- src/
- App.vue
- main.js
- static/
- data.json
- assets/
- data.json
- .gitignore
- babel.config.js
- package.json
- README.md
babel.config.js looks like this: babel.config.js看起来像这样:
module.exports = {
presets: [
'@vue/app'
]
}
And package.json is just that simple: 而package.json就这么简单:
{
"name": "test-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.6.9",
"vuetify": "^1.5.6"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.5.1",
"@vue/cli-plugin-eslint": "^3.5.1",
"@vue/cli-service": "^3.5.1",
"babel-eslint": "^10.0.1",
"eslint": "^5.15.2",
"eslint-plugin-vue": "^5.2.2",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vue-template-compiler": "^2.6.9"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
Finally, I build my application with this command: 最后,我使用以下命令构建应用程序:
$ npm run build
As a result I get dist
folder. 结果,我得到了
dist
文件夹。 However, as I can see there is no assets
or static
folder inside it. 但是,正如我所见,其中没有
assets
或static
文件夹。 So, when I go to http://localhost/static/data.json
or http://localhost/assets/data.json
I get this error message: 因此,当我转到
http://localhost/static/data.json
或http://localhost/assets/data.json
以下错误消息:
The requested URL /static/data.json was not found on this server.
在此服务器上找不到请求的URL /static/data.json。
How can I fix it? 我该如何解决?
may it works for you add this to your web-pack.production.js
可能适用于您将其添加到
web-pack.production.js
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.assetsSubDirectory,
ignore: ['.*'],
},
]),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.