diff --git a/dist/index.js b/dist/index.js index 169183b..8f3cbdc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8,6 +8,10 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); +var _isEmpty2 = require('lodash/isEmpty'); + +var _isEmpty3 = _interopRequireDefault(_isEmpty2); + var _forEach2 = require('lodash/forEach'); var _forEach3 = _interopRequireDefault(_forEach2); @@ -18,10 +22,6 @@ var _merge3 = _interopRequireDefault(_merge2); var _htmlMinifier = require('html-minifier'); -var _isGlob = require('is-glob'); - -var _isGlob2 = _interopRequireDefault(_isGlob); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var DEFAULT_CONFIG = { @@ -35,11 +35,11 @@ exports.default = function (options, modified, total, fisDeployNextEvent) { ignorePattern = config.ignorePattern, minifyOptions = (0, _objectWithoutProperties3.default)(config, ['templatePattern', 'ignorePattern']); - var isTemplatePatternGlobVerified = (0, _isGlob2.default)(templatePattern); - var isIgnorePatternGlobVerified = (0, _isGlob2.default)(ignorePattern); + var isTemplatePatternVerified = !(0, _isEmpty3.default)(templatePattern); + var isIgnorePatternVerified = !(0, _isEmpty3.default)(ignorePattern); (0, _forEach3.default)(modified, function (modifiedFile) { - if (modifiedFile.release && (!isTemplatePatternGlobVerified ? modifiedFile.isHtmlLike : fis.util.glob(templatePattern, modifiedFile.subpath)) && isIgnorePatternGlobVerified && !fis.util.glob(ignorePattern, modifiedFile.subpath)) { + if (modifiedFile.release && (!isTemplatePatternVerified ? modifiedFile.isHtmlLike : fis.util.glob(templatePattern, modifiedFile.subpath)) && (!isIgnorePatternVerified || isIgnorePatternVerified && !fis.util.glob(ignorePattern, modifiedFile.subpath))) { var fileContent = modifiedFile.getContent(); modifiedFile.setContent((0, _htmlMinifier.minify)(fileContent, minifyOptions)); } diff --git a/package.json b/package.json index f78e500..1f102f2 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,6 @@ }, "dependencies": { "html-minifier": "^3.5.3", - "glob": "^7.1.2", - "is-glob": "^4.0.0", "lodash": "^4.17.4" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index 5d863da..fd595d9 100644 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,7 @@ */ import { minify } from 'html-minifier'; -import isGlob from 'is-glob'; -import { merge, forEach } from 'lodash'; +import { merge, forEach, isEmpty } from 'lodash'; /** * @type {Object} DEFAULT_CONFIG - 插件默认配置 @@ -34,8 +33,8 @@ const DEFAULT_CONFIG = { export default (options, modified, total, fisDeployNextEvent) => { const config = merge(DEFAULT_CONFIG, options); const { templatePattern, ignorePattern, ...minifyOptions } = config; - const isTemplatePatternGlobVerified = isGlob(templatePattern); - const isIgnorePatternGlobVerified = isGlob(ignorePattern); + const isTemplatePatternVerified = !isEmpty(templatePattern); + const isIgnorePatternVerified = !isEmpty(ignorePattern); /** * @see http://fis.baidu.com/fis3/api/fis.file-File.html * @@ -68,15 +67,18 @@ export default (options, modified, total, fisDeployNextEvent) => { modifiedFile.release && ( // 如果没有过滤的正则,则依据`isHtmlLike`来鉴别 - (!isTemplatePatternGlobVerified) ? + (!isTemplatePatternVerified) ? modifiedFile.isHtmlLike : // eslint-disable-next-line no-undef fis.util.glob(templatePattern, modifiedFile.subpath) ) && ( - isIgnorePatternGlobVerified && - // eslint-disable-next-line no-undef - !fis.util.glob(ignorePattern, modifiedFile.subpath) + !isIgnorePatternVerified || + ( + isIgnorePatternVerified && + // eslint-disable-next-line no-undef + !fis.util.glob(ignorePattern, modifiedFile.subpath) + ) ) ) { const fileContent = modifiedFile.getContent(); diff --git a/yarn.lock b/yarn.lock index 9aacd33..362713d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2292,10 +2292,6 @@ is-extglob@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0" -is-extglob@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" - is-finite@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa" @@ -2318,12 +2314,6 @@ is-glob@^2.0.0, is-glob@^2.0.1: dependencies: is-extglob "^1.0.0" -is-glob@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.0.tgz#9521c76845cc2610a85203ddf080a958c2ffabc0" - dependencies: - is-extglob "^2.1.1" - is-my-json-valid@^2.12.4: version "2.16.1" resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.1.tgz#5a846777e2c2620d1e69104e5d3a03b1f6088f11"