config/indexjs详解上代码:

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation. const path = require('path') module.exports = {
dev: { // Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
// 代理作用是用来建一个虚拟api服务器用来代理本机的请求,只能用于本地开发模式
proxyTable: {
'/api': {
target: 'http://10.0.111.111:9999', //要访问的后端接口
changeOrigin: true,
pathRewrite: {
'^/api': 'http://10.0.111.111:9999'
}
}
},
// 原本是localhost可以配置成自己的ip
host: '10.98.15.99',
// dev-server的端口号,可以自行更改
port: 9898,
// 是否自动打开浏览器
autoOpenBrowser: true,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- //是否使用语法检测
useEslint: true,
// 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-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,
//是否生成css,map文件,上面这段英文就是说使用这个cssmap可能存在问题,但是按照经验,问题不大,可以使用
//一般false处理
cssSourceMap: true
}, build: {
//下面是相对路径的拼接,假如当前跟目录是config,那么下面配置的index属性的属性值就是dist/index.html
index: path.resolve(__dirname, '../dist/index.html'), //下面定义的是静态资源的根目录 也就是dist目录
assetsRoot: path.resolve(__dirname, '../dist'),
// 下面定义的是静态资源根目录的子目录static,也就是dist目录下面的static
assetsSubDirectory: 'static',
// 下面定义的是静态资源的公开路径,也就是真正的引用路径,一般会加'./'
assetsPublicPath: '/', /**
* Source Maps
*/
//下面定义是否生成生产环境的sourcmap,sourcmap是用来debug编译后文件的,通过映射到编译前文件来实现
//map文件的作用在于:项目打包后,代码都是经过压缩加密的,如果运行时报错,输出的错误信息无法准确得知是哪里的代码报错。
//有了map就可以像未加密的代码一样,准确的输出是哪一行哪一列有错
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map', // 下面是是否在生产环境中压缩代码,如果要压缩必须安装compression-webpack-plugin
// npm install --save-dev compression-webpack-plugin
productionGzip: false, // 下面定义要压缩哪些类型的文件
productionGzipExtensions: ['js', 'css'], // 下面是用来开启编译完成后的报告,可以通过设置值为true和false来开启或关闭
// 下面的process.env.npm_config_report表示定义的一个npm_config_report环境变量,可以自行设置
bundleAnalyzerReport: process.env.npm_config_report
}
}

webpack.base.conf.js注解:

'use strict'
const path = require('path') // 引入nodejs路径模块
const utils = require('./utils')// 引入utils工具模块,utils主要用来处理css-loader和vue-style-loader的
const config = require('../config')// 引入config目录下的index.js配置文件,主要用来定义一些开发和生产环境的属性
const vueLoaderConfig = require('./vue-loader.conf')// vue-loader.conf配置文件是用来解决各种css文件的,定义了诸如css,less,sass之类的和样式有关的loader // 此函数是用来返回当前目录的平行目录的路径,因为有个'..'
function resolve (dir) {
return path.join(__dirname, '..', dir)
} // 配置eslint检测
const createLintingRule = () => ({
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: require('eslint-friendly-formatter'),
emitWarning: !config.dev.showEslintErrorsInOverlay
}
}) module.exports = {
context: path.resolve(__dirname, '../'),
//文件入口配置
entry: {
app: ["babel-polyfill", "./src/main.js"] //ie11下白屏或者说es6转码都行 入口文件是src目录下的main.js
},
//文件出口配置
output: {
path: config.build.assetsRoot,// 路径是config目录下的index.js中的build配置中的assetsRoot,也就是dist目录
filename: '[name].js',// 文件名称这里使用默认的name也就是main
publicPath: process.env.NODE_ENV === 'production' // 上线地址,也就是真正的文件引用路径,如果是production生产环境,其实这里都是 '/'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],// 省略扩展名,也就是说.js,.vue,.json文件导入可以省略后缀名,这会覆盖默认的配置,所以要省略扩展名在这里一定要写上
alias: {
//配置别名,后面的$符号指精确匹配,也就是说只能使用 import vuejs from "vue" 这样的方式导入vue.esm.js文件,不能在后面跟上 vue/vue.js
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
// module用来解析不同的模块 插件配置项都在这了
module: {
rules: [
// ...(config.dev.useEslint ? [createLintingRule()] : []), //语法检测
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
//node主要是阻止一些webpack的默认注入行为,因为在vue中,已经具备了这些功能;
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}

vue-cli下面的config/index.js注解 webpack.base.conf.js注解的更多相关文章

  1. vue-cli脚手架build目录中的webpack.base.conf.js配置文件

    转载自:http://www.cnblogs.com/ye-hcj/p/7082620.html webpack.base.conf.js配置文件// 引入nodejs路径模块 var path = ...

  2. vue-cli脚手架npm相关文件解读(1)webpack.base.conf.js

    系列文章传送门: 1.build/webpack.base.conf.js 2.build/webpack.prod.conf.js 3.build/webpack.dev.conf.js 4.bui ...

  3. vue-cli 2.x脚手架build目录中的webpack.base.conf.js配置文件

    此文章用来解释vue-cli脚手架build目录中的webpack.base.conf.js配置文件,适用于vue-cli 2.x版本 此配置文件是vue开发环境的wepack相关配置文件,主要用来处 ...

  4. vue-cli脚手架之webpack.base.conf.js

    webpack相关的重要配置文件将在这一节给出.webpack水很深啊^o^,在此先弄清楚原配文件内容的含义,后续可以自己根据实际情况配置. webpack.base.conf.js:配置vue开发环 ...

  5. 手撕vue-cli配置——webpack.base.conf.js篇

    在开始写webpack.base.conf.js(简称base)之前,我们先来看一下vue-loader.conf.js这个文件,毕竟在base中我们还会用到: 'use strict' //引入前一 ...

  6. vue - webpack.base.conf.js

    描述:webapck基本配置文件. 为了给开发文件和打包文件(webpack.dev.conf.js|| webpack.prod.conf.js) 提供方便. 'use strict' // 路径 ...

  7. vue --- 脚手架初始化项目中配置文件webpack.base.conf.js代码含义

    'use strict' //引入node path 中间件 可以获取到 path 路径的一些信息 const path = require('path') //引入utils工具模块 utils主要 ...

  8. webpack.base.conf.js

    var path = require('path')var utils = require('./utils')var config = require('../config')var vueLoad ...

  9. 【webpack】webpack.base.conf.js基础配置

    var path = require('path') // node路径模块 var utils = require('./utils') // 对vue-loader对于css预编译一些提取的工具模 ...

随机推荐

  1. pkg-config相关

    编译fuse的命令 gcc myfuse.c -o myfuse `pkg-config fuse --cflags --libs` 中的 pkg-config fuse --cflags --lib ...

  2. 一个点亮屏幕的service

    这个版本是只能点亮不能解锁的版本(注意很多句子都被注释掉了,那部分是用来实现解锁屏幕的),达到了预期的效果,特此纪念. 把代码贴出来: package com.larry.msglighter; im ...

  3. 你真的懂redis吗?

    Redis在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在Redis的使用和原理方面对小伙伴们进行各种刁难.作为一名在互联网技术行业打击过成百上千名[请允许我夸张一下]的资深技术面试官 ...

  4. MySQL_详细基本操作命令

    mysql 修改新密码:use mysql:update user set password='新密码' where user='用户名':flush privileges:  更新权限 增加新用户: ...

  5. Hackerrank: Week of Code 36

    Cut a Strip 题目简述:给定$n \times m$的矩阵$a[][]$,要求选择一个$x \times 1(1 \leq x \leq k)$的(连续)子矩阵并清零后,找到最大和的(连续) ...

  6. SPOJ FIBOSUM && FIBOSUM2

    Fibonacci数列定义为 $$f_n = f_{n-1}+f_{n-2}, \text{以及初值}f_0=0, f_1=1.$$ 本文之讨论,皆在模$10^9+7$意义下. FIBOSUM 给定$ ...

  7. 任务48:Identity MVC:Model后端验证

    任务48:Identity MVC:Model后端验证 RegisterViewModel using System; using System.Collections.Generic; using ...

  8. poj 1988 Cube Stacking【带权并查集】

    设s[x]为x所在栈里的个数,c[x]表示x下面有几个,合并的时候直接合并s,然后路径压缩的时候更新c即可 #include<iostream> #include<cstdio> ...

  9. SpringSercurity基础

    创建 spring 配置文件 spring-security.xml intercept-url 表示拦截页面    /*  表示的是该目录下的资源,只包括本级目录不包括下级目录 /** 表示的是该目 ...

  10. chrome调试中resource改到application中了

    如题,看视频的时候发现在resource下面查看cookie,但是自己试的时候发现没有了这个工具, google之后发现原来该位置了