vue+element踩坑记-项目build打包以后入口文件显示空白的解决方案

现象描述

我在准备测试一个项目的时候,需要打包给后端使用, 我打完包以后发现,入口文件,也就是这个文件
dist
该文件是直接打不开的,那么我之前是遇到过的,此类的问题,开始是认为是router.js里面的mode改变了导致的,也就是我们在配置路由的时候是可以直接将mode:history的,在路由文件里面,但是我改变以后发现还是不行的,后来百度了以后发现是因为其中有一个文件是不对的,需要我们在配置文件里面将一个文件的指向改变一下
也就是这里 。位置是config下的index.js文件

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    
    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,

    cssSourceMap: true
  },

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}

上面的build中,需要在assetsPublicPath后面的/前面加上.
就这么简单

我写的可能不那么的全面,我只是用这样的办法解决了,目前暂且认为是可以的,以后有大神的话,可以交流一下,毕竟我只是一个vue的小白。

发布了189 篇原创文章 · 获赞 455 · 访问量 86万+

猜你喜欢

转载自blog.csdn.net/qq_41485414/article/details/91886938