diff --git a/lib/loader.js b/lib/loader.js index 3117b68..4e34854 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -5,11 +5,12 @@ const SVGCompiler = require('svg-baker'); const { NAMESPACE } = require('./config'); const configure = require('./configurator'); const Exceptions = require('./exceptions'); +const fileTypeDetect = require('./utils/file-type-detect'); let svgCompiler = new SVGCompiler(); // eslint-disable-next-line consistent-return -module.exports = function loader(content) { +module.exports = function loader(contentBuffer) { if (this.cacheable) { this.cacheable(); } @@ -24,7 +25,13 @@ module.exports = function loader(content) { const parentCompiler = isChildCompiler ? compiler.parentCompilation.compiler : null; const matchedRules = getOptions(loaderContext); - if (!content.includes(' { const runtime = runtimeGenerator({ symbol, config, context: loaderContext.context, loaderContext }); done(null, runtime); @@ -80,3 +91,5 @@ module.exports = function loader(content) { }; module.exports.NAMESPACE = NAMESPACE; + +module.exports.raw = true; diff --git a/lib/utils/file-type-detect.js b/lib/utils/file-type-detect.js new file mode 100644 index 0000000..b79bb01 --- /dev/null +++ b/lib/utils/file-type-detect.js @@ -0,0 +1,27 @@ +const imageSize = require('image-size'); + +/** + * detect whether content is an image + * @param {Buffer} content + * @return {boolean} + */ +function isImage(content) { + try { + imageSize(content); + return true; + } catch (err) { + return false; + } +} + +/** + * detect whether content is an image + * @param {string} content + * @return {boolean} + */ +function isSVG(content) { + return content.includes('=0.0.4" -source-map@^0.6.1, source-map@~0.6.1: +source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1: + version "0.5.7" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" + +source-map@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -7333,7 +7142,7 @@ through2@^2.0.2: readable-stream "^2.1.5" xtend "~4.0.1" -through@2, "through@>=2.2.7 <3", through@^2.3.6, through@~2.3.6: +through@2, "through@>=2.2.7 <3", through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= @@ -7397,10 +7206,6 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" -toposort@^1.0.0: - version "1.0.7" - resolved "https://registry.yarnpkg.com/toposort/-/toposort-1.0.7.tgz#2e68442d9f64ec720b8cc89e6443ac6caa950029" - tough-cookie@~2.3.0: version "2.3.4" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655" @@ -7482,13 +7287,6 @@ ua-parser-js@^0.7.9: version "0.7.17" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac" -uglify-js@3.4.x: - version "3.4.2" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.2.tgz#70511a390eb62423675ba63c374ba1abf045116c" - dependencies: - commander "~2.15.0" - source-map "~0.6.1" - uglify-js@^2.6: version "2.8.29" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" @@ -7630,21 +7428,6 @@ util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= -util.promisify@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/util.promisify/-/util.promisify-1.0.0.tgz#440f7165a459c9a16dc145eb8e72f35687097030" - dependencies: - define-properties "^1.1.2" - object.getownpropertydescriptors "^2.0.3" - -utila@~0.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/utila/-/utila-0.3.3.tgz#d7e8e7d7e309107092b05f8d9688824d633a4226" - -utila@~0.4: - version "0.4.0" - resolved "https://registry.yarnpkg.com/utila/-/utila-0.4.0.tgz#8a16a05d445657a3aea5eecc5b12a4fa5379772c" - uuid@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"