账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue-cli执行npm run build之后无法本地预览的问题
    42
    0

    生成dist成功,并且路径也已经改成了assetsPublicPath:‘./’依然无法本地预览

    之前用VUE写过一个点餐系统,用同样的方式进行了打包可以本地预览,但是这一次写的租房系统经过打包以后无法本地预览,只可以服务器模式打开预览,因此打包spaAPP受阻,出现的总是白页,请问有没有人遇到过这种情况。附上打包的配置。

    'use strict'
    // Template version: 1.1.3
    // see http://vuejs-templates.github.io/webpack for documentation.
    
    const path = require('path')
    
    module.exports = {
      build: {
        env: require('./prod.env'),
        index: path.resolve(__dirname, '../dist/index.html'),
        assetsRoot: path.resolve(__dirname, '../dist'),
        assetsSubDirectory: 'static',
        assetsPublicPath: './',
        productionSourceMap: true,
        // 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
      },
      dev: {
        env: require('./dev.env'),
        port: process.env.PORT || 8080,
        autoOpenBrowser: true,
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: {},
        // 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
      }
    }
    
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 耀月星 普通会员 1楼

      在 Vue CLI 中,如果你想要在本地预览你的构建后的项目,你可以使用 npm run serve 命令。这将启动一个服务器,你可以通过浏览器访问这个服务器的 IP 地址来预览你的项目。

      但是,如果你想在浏览器中预览你的项目,你需要将你的项目的静态资源(如图片、CSS 和 JavaScript 文件)放到 public 目录中。然后,你可以通过访问你的项目的 URL 来预览你的项目。

      例如,如果你的项目文件夹结构如下:

      project src main.js static images image1.jpg image2.jpg css style.css js script.js build

      你可以使用以下命令来预览你的项目:

      npm run build

      这将会把 build 目录下的所有文件打包成一个 dist 目录。然后,你可以通过访问 http://localhost:8080/dist 来预览你的项目。

      注意,如果你的项目文件夹结构中有一个 package.json 文件,那么你需要先安装 npm 才能使用 npm run build 命令。你可以通过以下命令来安装 npm

      npm install -g npm

      如果你的项目依赖于外部的依赖,例如一个第三方库,那么你需要先安装这个依赖,然后再使用 npm run build 命令。你可以通过以下命令来安装这个依赖:

      npm install <dependency-name>

      例如,如果你的项目依赖于一个名为 axios 的库,你可以通过以下命令来安装这个库:

      npm install axios

    • 桃花仙人儿 普通会员 2楼

      在 Vue CLI 中,如果你想要在本地预览你的构建后的项目,你可以使用 npm run serve 命令。这将启动一个服务器,你可以通过浏览器访问这个服务器的 IP 地址来预览你的项目。

      但是,如果你想在浏览器中预览你的项目,你需要将你的项目的静态资源(如图片、CSS 和 JavaScript 文件)放到 public 目录中。然后,你可以通过访问你的项目的 URL 来预览你的项目。

      例如,如果你的项目文件夹结构如下:

      project src main.js static images image1.jpg image2.jpg css style.css js script.js build

      你可以使用以下命令来预览你的项目:

      npm run build

      这将会把 build 目录下的所有文件打包成一个 dist 目录。然后,你可以通过访问 http://localhost:8080/dist 来预览你的项目。

      注意,如果你的项目文件夹结构中有一个 package.json 文件,那么你需要先安装 npm 才能使用 npm run build 命令。你可以通过以下命令来安装 npm

      npm install -g npm

      如果你的项目依赖于外部的依赖,例如一个第三方库,那么你需要先安装这个依赖,然后再使用 npm run build 命令。你可以通过以下命令来安装这个依赖:

      npm install <dependency-name>

      例如,如果你的项目依赖于一个名为 axios 的库,你可以通过以下命令来安装这个库:

      npm install axios

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部