Skip to content

Commit

Permalink
Merge pull request #3 from Yona-Appletree/master
Browse files Browse the repository at this point in the history
Fix for #2: Adding support for excluding <link> tags
  • Loading branch information
jamesjieye authored Dec 7, 2016
2 parents cf8157f + 8814434 commit 1f65ba8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.exclude {
font-size: 24px;
}
10 changes: 6 additions & 4 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
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 1f65ba8

Please sign in to comment.