【问题标题】:Vue cli build show blank page - Apache serverVue cli build 显示空白页 - Apache 服务器
【发布时间】:2022-01-14 19:53:37
【问题描述】:

vue cli 有一些问题。当我运行 npm run serve 时,一切都很顺利。当我进入开发模式时,npm run build-dev,构建过程完成。我有一个空白页。

错误信息是“Uncaught SyntaxError: Unexpected token '

以下是我的设置: 打包.json

{
  "name": "gold",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "test:unit": "vue-cli-service test:unit",
    "lint": "vue-cli-service lint",
    "build-dev": "vue-cli-service build --mode production-dev",
    "build-production": "vue-cli-service build"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "babel-polyfill": "^6.26.0",
    "camelize2": "^1.0.0",
    "core-js": "^3.6.5",
    "element-ui": "^2.15.5",
    "vue": "^2.6.14",
    "vue-carousel": "^0.18.0",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-standard": "^5.1.2",
    "@vue/test-utils": "^1.0.3",
    "babel-eslint": "^10.1.0",
    "babel-plugin-component": "^1.1.1",
    "eslint": "^6.8.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^6.2.2",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "^2.6.14",
    "webpack-bundle-analyzer": "^3.9.0"
  }
}

vue.config.js

// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
//   .BundleAnalyzerPlugin

module.exports = {
  // options...
  // configureWebpack: {
  //   plugins: [new BundleAnalyzerPlugin()]
  // },
  // configureWebpack: {
  //   optimization: {
  //     runtimeChunk: 'single',
  //     splitChunks: {
  //       chunks: 'all',
  //       maxInitialRequests: Infinity,
  //       minSize: 0,
  //       cacheGroups: {
  //         vendor: {
  //           test: /[\\/]node_modules[\\/]/,
  //           name(module) {
  //             // get the name. E.g. node_modules/packageName/not/this/part.js
  //             // or node_modules/packageName
  //             const packageName = module.context.match(
  //               /[\\/]node_modules[\\/](.*?)([\\/]|$)/
  //             )[1]

  //             // npm package names are URL-safe, but some servers don't like @ symbols
  //             return `npm.${packageName.replace('@', '')}`
  //           }
  //         }
  //       }
  //     }
  //   }
  // },
  devServer: {
    port: 8989
  },
  transpileDependencies: ['camelcase']
}

抱歉,如果我不能显示任何进一步的代码,谢谢。

【问题讨论】:

    标签: javascript node.js vue.js npm


    【解决方案1】:

    您似乎没有找到正确的路径。 尝试使用相对路径,例如

    module.exports = {
      productionSourceMap: false,  
      outputDir: '../dist',
      assetsDir: 'static',
      indexPath: 'src/index.html'
    };
    

    【讨论】:

    • 感谢您的帮助。我在 vue.config.js 中添加了它,但问题仍然存在。我没有运气。我已经在 bitbucket 中提取了这个项目。看来我的前同事在这种环境下工作得很好。但不知道为什么在我运行 npm build-dev 后它对我不起作用。
    猜你喜欢
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 2015-09-22
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多