Skip to content

Commit

Permalink
feat(mixins-attributes): inline* and inject* mixins now accept (attri…
Browse files Browse the repository at this point in the history
…butes)

e.g. inlineCSS(media="(min-width:200px)") adds media attribute to style tag
  • Loading branch information
Velenir committed Jan 15, 2017
1 parent 3ca2e48 commit b2fdb9d
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions mixins.pug
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mixin inject(filename, tag, searchWithin)
if currentTag === "link"
link(rel="stylesheet", href=file)&attributes(attributes)
else if currentTag === "script"
script(src=file)&attributes(attibutes)
script(src=file)&attributes(attributes)
else
#{currentTag}&attributes(attributes)

Expand All @@ -178,7 +178,8 @@ mixin inject(filename, tag, searchWithin)
inlines css resources from htmlWebpackPlugin.files,
except for already inlined or injected resources
@cssList can be a single filename string, RegExp or an array of them,
cssList strings starting with "!" are skipped
cssList strings starting with "!" are skipped;
also accepts attributes to be added to style tags, +inlineCSS(...)(attributes)
mixin inlineCSS(cssList)
if cssList === undefined
- cssList = Array.from(cssToInline);
Expand All @@ -189,15 +190,16 @@ mixin inlineCSS(cssList)
- var exclude = inclExcl.exclude;

- processRc(include, (css) => {
+inline(css, "style", htmlWebpackPlugin.files.css)
+inline(css, "style", htmlWebpackPlugin.files.css)&attributes(attributes)
- }, exclude);


//-
injects css resources from htmlWebpackPlugin.files,
except for already inlined or injected resources
@cssList can be a single filename string, RegExp or an array of them,
cssList strings starting with "!" are skipped
cssList strings starting with "!" are skipped;
also accepts attributes to be added to link tags, +injectCSS(...)(attributes)
mixin injectCSS(cssList)
if cssList === undefined
- cssList = Array.from(cssToInject);
Expand All @@ -208,15 +210,16 @@ mixin injectCSS(cssList)
- var exclude = inclExcl.exclude;

- processRc(include, (css) => {
+inject(css, "link", htmlWebpackPlugin.files.css)
+inject(css, "link", htmlWebpackPlugin.files.css)&attributes(attributes)
- }, exclude);


//-
inlines js resources from htmlWebpackPlugin.files,
except for already inlined or injected resources
@jsList can be a single filename string, RegExp or an array of them,
jsList strings starting with "!" are skipped
jsList strings starting with "!" are skipped;
also accepts attributes to be added to script tags, +inlineJS(...)(attributes)
mixin inlineJS(jsList)
if jsList === undefined
- jsList = Array.from(jsToInline);
Expand All @@ -227,15 +230,16 @@ mixin inlineJS(jsList)
- var exclude = inclExcl.exclude;

- processRc(include, (js) => {
+inline(js, "script", htmlWebpackPlugin.files.js)
+inline(js, "script", htmlWebpackPlugin.files.js)&attributes(attributes)
- }, exclude);


//-
injects js resources from htmlWebpackPlugin.files,
except for already inlined or injected resources
@jsList can be a single filename string, RegExp or an array of them,
jsList strings starting with "!" are skipped
jsList strings starting with "!" are skipped;
also accepts attributes to be added to script tags, +injectJS(...)(attributes)
mixin injectJS(jsList)
if jsList === undefined
- jsList = Array.from(jsToInject);
Expand All @@ -246,36 +250,38 @@ mixin injectJS(jsList)
- var exclude = inclExcl.exclude;

- processRc(include, (js) => {
+inject(js, "script", htmlWebpackPlugin.files.js)
+inject(js, "script", htmlWebpackPlugin.files.js)&attributes(attributes)
- }, exclude);


//-
inlines css resources from chunks passed in htmlWebpackPlugin.options.inline
and injects the rest, in the order they appear htmlWebpackPlugin.files
and injects the rest, in the order they appear htmlWebpackPlugin.files;
also accepts attributes to be added to link/style tags, +CSS(...)(attributes)
mixin CSS
each css in htmlWebpackPlugin.files.css
if injected.has(css) || inlined.has(css)
- continue;

if cssToInline.has(css)
+inline(css, "style")
+inline(css, "style")&attributes(attributes)
else if cssToInject.has(css)
+inject(css, "link")
+inject(css, "link")&attributes(attributes)


//-
inlines js resources from chunks passed in htmlWebpackPlugin.options.inline
and injects the rest, in the order they appear htmlWebpackPlugin.files
and injects the rest, in the order they appear htmlWebpackPlugin.files;
also accepts attributes to be added to script tags, +JS(...)(attributes)
mixin JS
each js in htmlWebpackPlugin.files.js
if injected.has(js) || inlined.has(js)
- continue;

if jsToInline.has(js)
+inline(js, "script")
+inline(js, "script")&attributes(attributes)
else if jsToInject.has(js)
+inject(js, "script")
+inject(js, "script")&attributes(attributes)


//-
Expand Down Expand Up @@ -327,7 +333,8 @@ mixin JS
inlines files of type @type from chunk with @chunkName name
@chunkName - a valid chunk name from htmlWebpackPlugin.files.chunks or an array of names
@type - can be "css" or "js", which inlines css or js files respectively,
otherwise inlines both types
otherwise inlines both types;
also accepts attributes to be added to style/script tags, +inlineChunk(...)(attributes)
mixin inlineChunk(chunkNames, type)
if !Array.isArray(chunkNames)
- chunkNames = [chunkNames];
Expand Down Expand Up @@ -368,7 +375,8 @@ mixin inlineChunk(chunkNames, type)
injects files of type @type from chunk with @chunkName name
@chunkName - a valid chunk name from htmlWebpackPlugin.files.chunks or an array of names
@type - can be "css" or "js", which injects css or js files respectively,
otherwise injects both types
otherwise injects both types;
also accepts attributes to be added to link/script tags, +injectChunk(...)(attributes)
mixin injectChunk(chunkNames, type)
if !Array.isArray(chunkNames)
- chunkNames = [chunkNames];
Expand Down

0 comments on commit b2fdb9d

Please sign in to comment.