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

feat: H5模板新增常量 VUE_APP_INDEX_CSS_HASH

上级 3e9f229b
......@@ -103,18 +103,39 @@ const PLATFORMS = {
copyWebpackOptions ({
assetsDir
}) {
const indexCssCopyOptions = [{
from: require.resolve('@dcloudio/uni-h5/dist/index.css'),
to: assetsDir,
transform (content) {
if (process.env.NODE_ENV === 'production') {
return content + getShadowCss()
}
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),
{
from: require.resolve('@dcloudio/uni-h5/dist/index.css'),
to: assetsDir,
transform (content) {
if (process.env.NODE_ENV === 'production') {
return content + getShadowCss()
}
return content
}
},
...indexCssCopyOptions,
...getCopyOptions(['hybrid/html'])
]
}
......@@ -564,4 +585,4 @@ module.exports = {
getPlatformSass () {
return SASS
}
}
}
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小程序 强制自定义组件模式
......@@ -259,7 +262,7 @@ moduleAlias.addAlias('mpvue-template-compiler', '@dcloudio/vue-cli-plugin-uni/pa
if (process.env.UNI_USING_V3 && process.env.UNI_PLATFORM === 'app-plus') {
moduleAlias.addAlias('vue-style-loader', '@dcloudio/vue-cli-plugin-uni/packages/app-vue-style-loader')
}
}
// vue cache
if ( // 非 h5 ,非 v3,非 native
......@@ -320,4 +323,4 @@ runByHBuilderX && console.log(`正在编译中...`)
module.exports = {
manifestPlatformOptions: platformOptions
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册