代码之家  ›  专栏  ›  技术社区  ›  Jacobian

Vuejs应用程序中缺少静态文件

  •  0
  • Jacobian  · 技术社区  · 5 年前

    我的第一个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。

    我怎么修?

    0 回复  |  直到 5 年前
        1
  •  2
  •   Hammad tariq    5 年前

    你能把这个加到你的 web-pack.production.js

    new CopyWebpackPlugin([
          {
            from: path.resolve(__dirname, '../static'),
            to: config.assetsSubDirectory,
            ignore: ['.*'],
          },
        ]),