Skip to content

Commit

Permalink
feat(core): Replace resource hash files in style
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinerer committed Dec 29, 2023
1 parent 9951e43 commit 072679f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/core/build/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const sourcemaps = require('gulp-sourcemaps')
const filter = require('gulp-filter')
const replace = require('gulp-replace')
const base64 = require('gulp-dataurl')
const revRewrite = require('gulp-rev-rewrite')
const header = require('gulp-header')
const sass = require('gulp-sass')(require('sass'))
const less = require('gulp-less')
Expand All @@ -16,12 +17,14 @@ const {
gulp,
_,
merge,
injectEnv
injectEnv,
readJsonFilesSync
} = require('@pipflow/utils')

const { pipeline, onDone } = require('../base/utils')
const { sassDefaultOptions } = require('../base/defaults')
const {
revDir,
createSrcOptions,
outputFiles,
plumber,
Expand All @@ -47,6 +50,13 @@ module.exports = function styleTask(options = {}, done) {
const basePath = getBasePath(input, options.base || '.') //合并文件后的基础路径
const cssFilter = filter('**/*.css', { restore: true })

let manifest
if (options.fileHash) {
// path.posix 统一路径, 兼容window平台
const json = readJsonFilesSync(path.posix.join(options.dest, revDir, '*.json'), { merge: true })
manifest = JSON.stringify(json)
}

/**
* 统一入口方式 (input支持 `string`, `array`, `object`)
* 流程分开处理 为了解决合并文件的问题
Expand Down Expand Up @@ -117,6 +127,11 @@ module.exports = function styleTask(options = {}, done) {
processes.push(base64(options.assetsInlineLimit))
}

// 3. 文件指纹处理
if (manifest) {
processes.push(revRewrite({ manifest }))
}

// 3. postcss //!需配置 `postcss.config.js` 和 `.browserslistrc`
const postcssPlugins = []
postcssPlugins.push(postcssEnv())
Expand Down

0 comments on commit 072679f

Please sign in to comment.