Skip to content

Commit

Permalink
Fix for #2: Adding support for excluding <link> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Yona Appletree committed Dec 6, 2016
1 parent cf8157f commit 8814434
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -44,13 +44,13 @@ HtmlWebpackExcludeAssetsPlugin.prototype.processAssets = function (excludePatter
var head = [];

pluginData.head.forEach(function (tag) {
if (!self.isExcluded(excludePatterns, tag.attributes.src)) {
if (!self.isExcluded(excludePatterns, tag.attributes.src || tag.attributes.href)) {
head.push(tag);
}
});

pluginData.body.forEach(function (tag) {
if (!self.isExcluded(excludePatterns, tag.attributes.src)) {
if (!self.isExcluded(excludePatterns, tag.attributes.src || tag.attributes.href)) {
body.push(tag);
}
});
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/exclude.css
@@ -0,0 +1,3 @@
.exclude {
font-size: 24px;
}
10 changes: 6 additions & 4 deletions spec/index.spec.js
Expand Up @@ -50,7 +50,8 @@ describe('HtmlWebpackExcludeAssetsPlugin', function () {
webpack({
entry: {
app: path.join(__dirname, 'fixtures', 'entry.js'),
style: [path.join(__dirname, 'fixtures', 'app.css')]
styleInclude: path.join(__dirname, 'fixtures', 'app.css'),
styleExclude: path.join(__dirname, 'fixtures', 'exclude.css')
},
output: {
path: OUTPUT_DIR,
Expand All @@ -62,7 +63,7 @@ describe('HtmlWebpackExcludeAssetsPlugin', function () {
plugins: [
new ExtractTextPlugin('[name].css'),
new HtmlWebpackPlugin({
excludeAssets: [/style.*.js/]
excludeAssets: [/styleInclude.*.js/, /styleExclude.*.css/]
}),
new HtmlWebpackExcludeAssetsPlugin()
]
Expand All @@ -72,8 +73,9 @@ describe('HtmlWebpackExcludeAssetsPlugin', function () {
fs.readFile(htmlFile, 'utf8', function (er, data) {
expect(er).toBeFalsy();
var $ = cheerio.load(data);
expect($('script[src="style.js"]').toString()).toBe('');
expect($('link[href="style.css"]').toString()).toBe('<link href="style.css" rel="stylesheet">');
expect($('script[src="styleInclude.js"]').toString()).toBe('');
expect($('link[href="styleInclude.css"]').toString()).toBe('<link href="styleInclude.css" rel="stylesheet">');
expect($('link[href="styleExclude.css"]').toString()).toBe('');
done();
});
});
Expand Down

0 comments on commit 8814434

Please sign in to comment.