This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wxss):border rpx clean-css/clean-css#1073
- Loading branch information
Showing
7 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
///@ts-check | ||
"use strict"; | ||
const path = require('path'); | ||
const through = require('through2'); | ||
|
||
// const applySourceMap = require('vinyl-sourcemaps-apply'); | ||
const CleanCSS = require('../../vendor/clean-css/clean'); | ||
const PluginError = require('./error'); | ||
|
||
module.exports = (options, callback) => { | ||
|
||
let _callback = callback || (o => undefined); | ||
|
||
return through.obj(function (file, enc, cb) { | ||
|
||
let _options = Object.assign({}, options || {}); | ||
|
||
if (file.isNull()) { | ||
return cb(null, file); | ||
} | ||
if (file.isStream()) { | ||
this.emit('error', new PluginError('gulp-clean-css', 'Streaming not supported!')); | ||
return cb(null, file); | ||
} | ||
|
||
if (file.sourceMap) { | ||
_options.sourceMap = JSON.parse(JSON.stringify(file.sourceMap)); | ||
} | ||
|
||
const content = { | ||
[file.path]: {styles: file.contents ? file.contents.toString() : ''} | ||
}; | ||
if (!_options.rebaseTo && _options.rebase !== false) { | ||
_options.rebaseTo = path.dirname(file.path); | ||
} | ||
|
||
// @ts-ignore | ||
new CleanCSS(_options).minify(content, (errors, css) => { | ||
|
||
if (errors) { | ||
return cb(errors.join(' ')); | ||
} | ||
|
||
let details = { | ||
'stats': css.stats, | ||
'errors': css.errors, | ||
'warnings': css.warnings, | ||
'path': file.path, | ||
'name': file.path.split(file.base)[1] | ||
}; | ||
|
||
if (css.sourceMap) { | ||
details['sourceMap'] = css.sourceMap; | ||
} | ||
_callback(details); | ||
|
||
file.contents = Buffer.from(css.styles); | ||
|
||
if (css.sourceMap) { | ||
const iMap = JSON.parse(css.sourceMap); | ||
const oMap = Object.assign({}, iMap, { | ||
file: path.relative(file.base, file.path), | ||
sources: iMap.sources.map(mapSrc => path.relative(file.base, mapSrc)) | ||
}); | ||
// applySourceMap(file, oMap); | ||
} | ||
cb(null, file); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
App({}) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.a { | ||
border: 2rpx solid green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.b{ | ||
padding-top: 0%; | ||
padding-left: 0%; | ||
padding-right: 0%; | ||
padding-bottom: 0%; | ||
} |