描述:开发时的配置.(配置开发时的一些操作)

例如这里,是否自动打开浏览器(默认true)

 'use strict'

 // build/util.js
const utils = require('./utils')
// node_modules里面的webpack
const webpack = require('webpack')
// config/index.js
const config = require('../config')
// 对象合并
const merge = require('webpack-merge')
// 路径
const path = require('path') // 引入webpack.base.conf.js配置
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder') // 配置
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT) const devWebpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map开发速度更快(只检测修改了的文件进行更新,而不是全部)
devtool: config.dev.devtool, /**
* 这里配置开发服务器
*/
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
],
},
// 是否开启HMR
hot: true,
// 内容
contentBase: false, // 因为我们使用CopyWebpackPlugin
// 是否压缩
compress: true, host: HOST || config.dev.host,
port: PORT || config.dev.port, // config => config/index.js
open: config.dev.autoOpenBrowser, overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
// 如果不开启,则不提示友好的错误信息!
quiet: true, // FriendlyErrorsPlugin所必需的
watchOptions: {
poll: config.dev.poll,
}
}, /**
* 配置插件
*/
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR在更新时在控制台中显示正确的文件名。
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
// 复制到自定义静态源
new CopyWebpackPlugin([
{
// 来自(可以是对象,可以是String)
from: path.resolve(__dirname, '../static'),
// 走向(可以是对象,可以是String)
to: config.dev.assetsSubDirectory,
// 忽略此类文件
ignore: ['.*']
}
])
]
}) /**
* 模块导出(Promise)
*/
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port
portfinder.getPort((err, port) => { if (err) {
reject(err)
} else {
// 发布新的端口,这是e2e测试所必需的
process.env.PORT = port
// 添加开发服务器到端口地址
devWebpackConfig.devServer.port = port // 添加 FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
onErrors: config.dev.notifyOnErrors
? utils.createNotifierCallback()
: undefined
})) resolve(devWebpackConfig)
}
})
})

vue - webpack.dev.conf.js的更多相关文章

  1. vue - webpack.dev.conf.js for merge

    webpack-merge提供了一个merge连接数组并合并创建新对象的对象的函数.如果遇到函数,它将执行它们,通过算法运行结果,然后再次将返回的值包装在函数中. 这种行为在配置webpack时特别有 ...

  2. vue - webpack.dev.conf.js for FriendlyErrorsPlugin

    描述:webpack网页端友好的报错信息就来自它 官网:https://www.npmjs.com/package/friendly-errors-webpack-plugin new Friendl ...

  3. vue - webpack.dev.conf.js for HtmlWebpackPlugin

    描述: 这是一个webpack插件,可以简化HTML文件的创建,为您的webpack捆绑服务提供服务. 这对于webpack包含文件名中包含哈希值的bundle 来说尤其有用,它会更改每个编译. 您可 ...

  4. vue - webpack.dev.conf.js for CopyWebpackPlugin

    描述:将单个文件或整个目录复制到构建目录 官网地址:https://www.npmjs.com/package/copy-webpack-plugin // 复制到自定义静态源 new CopyWeb ...

  5. vue - webpack.dev.conf.js for node-portfinder

    描述:获取当前可用的port. (vue-cli配置好了,一旦端口被占用,报错,再次运行时会打开:8080+1,依次类推...8080+n) 官网地址:https://www.npmjs.com/pa ...

  6. VUE开发请求本地数据的配置,旧版本dev-server.js,新版本webpack.dev.conf.js

    VUE开发请求本地数据的配置,早期的vue-lic下面有dev-server.js和dev-client.js两文件,请求本地数据在dev-server.js里配置,最新的vue-webpack-te ...

  7. vue模拟后台数据,请求本地数据的配置(旧版本dev-server.js,新版本webpack.dev.conf.js)

    最近学习一个vue-cli的项目,需要与后台进行数据交互,这里使用本地json数据来模仿后台数据交互流程.然而发现build文件夹下没有dev-server.js文件了,因为新版本的vue-webpa ...

  8. vue -- 脚手架之webpack.dev.conf.js

    webpack.dev.conf.js  开发环境模式配置文件: 'use strict'//js按照严格模式执行 const utils = require('./utils')//导入utils. ...

  9. webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

    vue 项目 npm run dev 运行时报错: npm ERR! xxx@1.0.0 dev: `webpack-dev-server --inline --progress --config b ...

随机推荐

  1. 乱侃OOD

    接口代表的就是共同性,所谓面向接口编程,就是要抽象各种不同概念的共同点 然后把这些概念的不同点用具体的类包装起来,这样一看,面向接口编程就等于面向对象编程 其实说白了是一个概念 IOC就是要把对细节的 ...

  2. python的版本会导致IBus设置(中文输入法)出错

    最近在学习python,可是,发现我的输入法 IBus-pinyin ,不能用了, 现象: 发现 “首选输入法”,根本点击不进去IBus设置的窗口,想去设置输入法都不行, IBus设置的窗口: 原因是 ...

  3. POJ 2253 Frogger【最短路变形/最小生成树的最大权/最小瓶颈树/A到B多条路径中的最小的最长边】

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  4. 【贪心】【线性基】bzoj2460 [BeiJing2011]元素

    题意:让你求一些数在XOR下的带权极大无关组. 带权极大无关组可以用贪心,将这些数按权值从大到小排序之后,依次检验其与之前的数是否全都线性无关.可以用线性基来搞. 可以用拟阵严格证明,不过也可以脑补一 ...

  5. [转]No configuration found for the specified action解决办法

    使用Struts2,配置一切正常,使用常用tag也正常,但是在使用<s:form>标记时,发现控制台总是输出警告信息, 警告信息内容如下: 警告: ...... <div> h ...

  6. [原创]MyEclipse2014全手动实现反向工程---解决手动整合ssh时发生的、在hibernate反向工程的时候找不到项目名的问题

    1.在MyEclipse2014中新建两个Web Project项目,名字分别为:Hibernate_manual和Hibernate_auto. 2.单击选中新建的Web项目Hibernate_au ...

  7. Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  8. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  9. KNN算法实现手写数字

    from numpy import * import operator from os import listdir def classify0(inX, dataSet, labels, k): d ...

  10. Ui Automator Test Through Command

    问题描述: 通过adb shell uiautomator runtest 命令,直接运行java测试例. 命令解析: adb shell uiautomator runtest <JARS&g ...