[英]How to manage missing static files with ExpressJS that serves a single page application?
[英]Static files are missing in VueJS application
我的第一個VueJS應用程序結構很簡單:
- src/
- App.vue
- main.js
- static/
- data.json
- assets/
- data.json
- .gitignore
- babel.config.js
- package.json
- README.md
babel.config.js看起來像這樣:
module.exports = {
presets: [
'@vue/app'
]
}
而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"
]
}
最后,我使用以下命令構建應用程序:
$ npm run build
結果,我得到了dist
文件夾。 但是,正如我所見,其中沒有assets
或static
文件夾。 因此,當我轉到http://localhost/static/data.json
或http://localhost/assets/data.json
以下錯誤消息:
在此服務器上找不到請求的URL /static/data.json。
我該如何解決?
可能適用於您將其添加到web-pack.production.js
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.assetsSubDirectory,
ignore: ['.*'],
},
]),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.