npm run build 打包成功,浏览器运行出错,请问各位有遇到过这种情况吗?

问题描述

npm run build 打包成功,浏览器运行出错,找不到您的文件 该文件可能已被移至别处或遭到删除。打开浏览器窗口会有当前电脑的绝对路径,不含host,post,的登录界面,但是一闪就只剩下路由路径/login,前面的计算机路径也不见了

问题出现的环境背景及自己尝试过哪些方法

用的是vue-element-admin,修改config下的一些配置,依然失败

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

config

// Various Dev Server settings

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

// Use Eslint Loader?
// If true, your code will be linted during bundling and
// linting errors and warnings will be shown in the console.
useEslint: false,
// If true, eslint errors and warnings will also be shown in the error overlay
// in the browser.
showEslintErrorsInOverlay: false,

/**
 * Source Maps
 */

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

// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false

},

build: {

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

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

$route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }

你期待的结果是什么?实际看到的错误信息又是什么?

有大佬遇到过吗?

阅读 3.3k
2 个回答

需要将build结果放置在服务器下,比如nginx服务目录下,单独使用鼠标点开是不行的

如果想在本地访问的话,需要在本地起一个服务器,可以用node安装一个http-server的包

推荐问题