vue-cli3的vue.config.js配置信息

之前所有的配置文件都在vue create 搭建时preset预设好的,后期可以通过vue config 命令来审查或修改全局的 CLI 配置 或 vue.config.js 中配置

更多配置详情参见官网:https://cli.vuejs.org/zh/config/

vue.config.js 是一个可选的配置文件,如果项目的(package.json同级的)根目录中存在这个文件,那么它会被@vue/cli-service自动加载。你也可以使用 package.json中的vue字段,但是注意这种写法需要你严格遵照 JSON 的格式来写。

vue.config.js这个文件应该导出一个包含了选项的对象:

module.exports = {

  // 选项...

}

 

 

配置代码如下

在vue根目录下创建vue.config.js文件

 

module.exports = {
    publicPath: '/',    //部署应用时的根路径(默认'/'),也可用相对路径(存在使用限制)
    outputDir: 'dist',        //运行时生成的生产环境构建文件的目录(默认'dist',构建之前会被清除)
    assetsDir: '',        //静态资源目录(js、css、img、fonts),相对outputDir的目录(默认'')
indexPath: 'index.html', //指定生成index.html的输出路径(相对outputDir)也可以是绝对路径
lintOnSave: true,                //是否开启ESlint(保存时检查)
    productionSourceMap: true,    //生产环境是否生成 sourceMap 文件
    pages: {    //pages里配置的路径和文件名在你的文档目录必须存在,否则启动服务会报错
        index: {//除了 entry 之外都是可选的
            entry: 'src/index/main.js',        //page的主入口
            template: 'public/index.html',    //模板来源
            filename: 'index.html',            //在 dist/index.html 的输出
//title在template中使用:<title><%=htmlWebpackPlugin.options.title%></title>
            title: '生成的配置信息',        
            chunks: ['chunk-vendors', 'chunk-common', 'index'] 
// 在这个页面中包含的块,默认情况下会包含,提取出来的通用 chunk 和 vendor chunk
        },
        subpage: 'src/subpage/main.js'
//官方解释:当使用只有入口的字符串格式时,模板会被推导为public/subpage.html
//若找不到就回退到public/index.html,输出文件名会被推导为subpage.html
    },
    css: {
        extract: true,        //是否使用css分离插件 ExtractTextPlugin
        sourceMap: false,    //开启 CSS source maps
        loaderOptions:{}, //css预设器配置项
        modules: false        //启用CSS modules for all css / pre-processor files.
    },
    devServer: {    //环境配置
        host: 'localhost',
        port: 8080,
        https: false,      //是否开启https
        hotOnly: false, //是否配置热更新
        open: true,      //配置自动启动浏览器
        proxy: {        //配置多个代理跨域(配置一个 proxy: 'http://localhost:4000' )
            '/api': {
                target: 'http://127.0.0.1:3000',
                ws: true,  //是否跨域
                changeOrigin: true,
            pathRewrite: { '^/api':'' }
            }
        }
    },
    pluginOptions: {// 第三方插件配置
        // ...
    }
};

猜你喜欢

转载自www.cnblogs.com/xuyx/p/11996699.html