修改vue+webpack run build的路径方法

作者:若晨工作室 时间:2024-04-28 10:54:08 

vue项目用webpack打包想要修改静态资源路径等,找到项目根目录下的config文件夹,打开该文件夹下的index.js文件,默认如下:


// see http://vuejs-templates.github.io/webpack for documentation.
var 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: 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
}
}

其中build.index:必须是本地文件系统上的绝对路径。会生成index.html文件。

build.assetsRoot:必须是本地文件系统上的绝对路径。

build.assetsSubDirectory:编译出来的资源文件。

build.assetsPublicPath:【资源的根目录】,这是通过http服务器运行的url路径。默认情况下,是根目录(/)。如果后台对静态资源url前缀要求,则需要改变这个路径。

build.productionSourceMap:在构建生产环境版本时是否开启source map。

来源:https://blog.csdn.net/wojiaomaxiaoqi/article/details/78478730

标签:vue,webpack,run,build
0
投稿

猜你喜欢

  • python自然语言处理之字典树知识总结

    2023-12-29 01:01:21
  • PyQT实现菜单中的复制,全选和清空的功能的方法

    2023-08-13 03:09:23
  • 利用pyinstaller打包exe文件的基本教程

    2022-06-09 12:32:13
  • python中的lambda函数用法指南

    2021-04-15 02:58:15
  • Python+MediaPipe实现检测人脸功能详解

    2021-05-05 15:34:17
  • asp 判断是否为搜索引擎蜘蛛的代码

    2011-03-10 11:03:00
  • 查找备注(text,ntext)类型字段为空的方法

    2008-08-02 12:47:00
  • SqlServer参数化查询之where in和like实现详解

    2012-05-22 18:10:50
  • 详解python环境安装selenium和手动下载安装selenium的方法

    2023-10-05 18:07:07
  • Python实现格式化输出的实例详解

    2023-03-15 10:01:59
  • 当达到输入长度时表单自动切换焦点

    2024-05-02 17:29:33
  • 基于 Serverless +企业微信打造 nCoV 疫情监控小助手

    2023-11-20 21:42:02
  • CentOS7.6安装MYSQL8.0的步骤详解

    2024-01-17 02:48:28
  • PHP遍历目录实现方法介绍

    2023-05-25 06:31:41
  • SQL Server中通过扩展存储过程实现数据库的远程备份与恢复

    2012-05-22 18:48:56
  • Yii框架引用插件和ckeditor中body与P标签去除的方法

    2024-05-11 09:25:19
  • Linux 修改Python命令的方法示例

    2023-10-04 18:16:58
  • 对Python函数设计规范详解

    2023-08-02 15:59:17
  • Windows 7下Python Web环境搭建图文教程

    2023-06-12 07:10:51
  • Python类class参数self原理解析

    2023-12-23 11:51:35
  • asp之家 网络编程 m.aspxhome.com