@@ -5,11 +5,12 @@ const SVGCompiler = require('svg-baker');
55const { NAMESPACE } = require ( './config' ) ;
66const configure = require ( './configurator' ) ;
77const Exceptions = require ( './exceptions' ) ;
8+ const isFileType = require ( './utils/is-file-type' ) ;
89
910let svgCompiler = new SVGCompiler ( ) ;
1011
1112// eslint-disable-next-line consistent-return
12- module . exports = function loader ( content ) {
13+ module . exports = function loader ( contentBuffer ) {
1314 if ( this . cacheable ) {
1415 this . cacheable ( ) ;
1516 }
@@ -24,7 +25,13 @@ module.exports = function loader(content) {
2425 const parentCompiler = isChildCompiler ? compiler . parentCompilation . compiler : null ;
2526 const matchedRules = getOptions ( loaderContext ) ;
2627
27- if ( ! content . includes ( '<svg' ) ) {
28+ const content = contentBuffer . toString ( ) ;
29+ const isSVG = isFileType . isSVG ( content ) ;
30+
31+ if (
32+ ! isSVG &&
33+ ! isFileType . isImage ( contentBuffer )
34+ ) {
2835 throw new Exceptions . InvalidSvg ( content , matchedRules ) ;
2936 }
3037
@@ -72,11 +79,17 @@ module.exports = function loader(content) {
7279 regExp : config . symbolRegExp
7380 } ) ;
7481 }
75- svgCompiler . addSymbol ( { id, content, path : resourcePath + resourceQuery } )
82+ svgCompiler . addSymbol ( {
83+ id,
84+ content : isSVG ? content : contentBuffer ,
85+ path : resourcePath + resourceQuery
86+ } )
7687 . then ( ( symbol ) => {
7788 const runtime = runtimeGenerator ( { symbol, config, context : loaderContext . context , loaderContext } ) ;
7889 done ( null , runtime ) ;
7990 } ) . catch ( done ) ;
8091} ;
8192
8293module . exports . NAMESPACE = NAMESPACE ;
94+
95+ module . exports . raw = true ;
0 commit comments