代码拉取完成,页面将自动刷新
/*
|--------------------------------------------------------------------------
| Browser-sync config file
|--------------------------------------------------------------------------
|
| For up-to-date information about the options:
| http://www.browsersync.io/docs/options/
|
| There are more options than you see here, these are just the ones that are
| set internally. See the website for more info.
|
|
*/
const config = require('./build-config')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
/**
* Require ./webpack.config.js and make a bundler from it
*/
const webpackConfig = require('./webpack.config')
const bundler = webpack(webpackConfig)
const browserSync = require('browser-sync').create()
const crypto = require('crypto')
const fileHashes = []
bundler.plugin('done', function (bundles) {
bundles.stats.forEach(function (stats, i) {
fileHashes[i] = fileHashes[i] || {}
checkAssets(stats, fileHashes[i])
})
})
function checkAssets (stats, bundleHashes) {
try {
const changedFiles = Object.keys(stats.compilation.assets)
.filter(name => {
const asset = stats.compilation.assets[name]
const md5Hash = crypto.createHash('md5')
const hash = md5Hash.update(asset.children ? asset.children[0]._value : asset.source()).digest('hex')
if (bundleHashes[name] !== hash) {
bundleHashes[name] = hash
return true
} else {
return false
}
})
browserSync.reload(changedFiles.map(name => `dist/${name}`))
} catch (e) {}
}
browserSync.init(Object.assign({
middleware: [
webpackDevMiddleware(bundler, Object.assign({
publicPath: webpackConfig[0].output.publicPath,
logLevel: 'silent'
}, config.webpackDevMiddleware))
]
}, config.browserSync))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。