提交 3f25dc85 编写于 作者: Q qiang

feat: H5模板新增常量 VUE_APP_INDEX_CSS_HASH

上级 3e9f229b
......@@ -103,9 +103,7 @@ const PLATFORMS = {
copyWebpackOptions ({
assetsDir
}) {
return [
...getStaticCopyOptions(assetsDir),
{
const indexCssCopyOptions = [{
from: require.resolve('@dcloudio/uni-h5/dist/index.css'),
to: assetsDir,
transform (content) {
......@@ -114,7 +112,30 @@ const PLATFORMS = {
}
return content
}
},
}]
const VUE_APP_INDEX_CSS_HASH = process.env.VUE_APP_INDEX_CSS_HASH
if (VUE_APP_INDEX_CSS_HASH) {
const {
getH5Options
} = require('./manifest')
const {
template
} = getH5Options()
const to = path.join(assetsDir, `[name].${VUE_APP_INDEX_CSS_HASH}.[ext]`)
if (process.env.NODE_ENV === 'production') {
const templateContent = fs.readFileSync(template, { encoding: 'utf8' })
if (/\bVUE_APP_INDEX_CSS_HASH\b/.test(templateContent)) {
indexCssCopyOptions[0].to = to
}
} else {
const indexCssCopyOption = Object.assign({}, indexCssCopyOptions[0])
indexCssCopyOption.to = to
indexCssCopyOptions.push(indexCssCopyOption)
}
}
return [
...getStaticCopyOptions(assetsDir),
...indexCssCopyOptions,
...getCopyOptions(['hybrid/html'])
]
}
......
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const loaderUtils = require('loader-utils')
// 初始化环境变量
const defaultInputDir = '../../../../src'
......@@ -109,6 +110,8 @@ if (process.env.UNI_PLATFORM === 'h5') {
process.env.UNI_OPT_PRELOAD = true
}
}
const buffer = fs.readFileSync(require.resolve('@dcloudio/uni-h5/dist/index.css'))
process.env.VUE_APP_INDEX_CSS_HASH = loaderUtils.getHashDigest(buffer, 'md5', 'hex', 8)
}
if (process.env.UNI_PLATFORM === 'mp-qq') { // QQ小程序 强制自定义组件模式
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册