vue项目的build文件夹的webpack.dev.conf.js文件说明

webpack配置开发环境中的入口

‘use strict’

const utils = require(’./utils’)

const webpack = require(‘webpack’)

const config = require(’…/config’)

const merge = require(‘webpack-merge’)//webpack-merge实现合并

const path = require(‘path’)

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’)//webpack的提示错误和日志信息的插件

const portfinder = require(‘portfinder’)// 查看空闲端口位置,默认情况下搜索8000这个端口

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 })

},

devtool: config.dev.devtool,//调试模式

devServer: {

clientLogLevel: ‘warning’,

historyApiFallback: {//使用 HTML5 History API 时, 404 响应替代为 index.html

rewrites: [

{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, ‘index.html’) },

],

},

hot: true,//热重载

contentBase: false, // 提供静态文件访问

compress: true,//压缩

host: HOST || config.dev.host,

port: PORT || config.dev.port,

open: config.dev.autoOpenBrowser,//npm run dev 时自动打开浏览器

overlay: config.dev.errorOverlay

? { warnings: false, errors: true }
false,// 显示warning 和 error 信息

publicPath: config.dev.assetsPublicPath,

proxy: config.dev.proxyTable,//api代理

quiet: true, //控制台打印警告和错误(用FriendlyErrorsPlugin 为 true)

watchOptions: {// 检测文件改动

poll: config.dev.poll,

}

},

plugins: [

new webpack.DefinePlugin({

‘process.env’: require(’…/config/dev.env’)

}),

new webpack.HotModuleReplacementPlugin(),//模块热替换插件,修改模块时不需要刷新页面

new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.

new webpack.NoEmitsPlugin(),//webpack编译错误的时候,中断打包进程,防止错误代码打包到文件中

// 将打包编译好的代码插入index.html

new HtmlWebpackPlugin({

filename: ‘index.html’,

template: ‘index.html’,

inject: true

}),

// 提取static assets 中css 复制到dist/static文件

new CopyWebpackPlugin([

{

from: path.resolve(__dirname, ‘…/static’),

to: config.dev.assetsSubDirectory,

ignore: [’.*’]//忽略.*的文件

}

])

]

})

module.exports = new Promise((resolve, reject) => {

portfinder.basePort = process.env.PORT || config.dev.port

portfinder.getPort((err, port) => { //查找端口号

if (err) {

reject(err)

} else {

//端口被占用时就重新设置evn和devServer的端口

process.env.PORT = port

devWebpackConfig.devServer.port = port

// npm run dev成功的友情提示

devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({

compilationSuccessInfo: {

messages: [Your application is running here: http://${devWebpackConfig.devServer.host}:${port}],

},

s: config.dev.notifys

? utils.createNotifierCallback()
undefined

}))

resolve(devWebpackConfig)

}

})

})

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值