-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure we work with HtmlWebpackExternalsPlugin
Test case for #97
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# HtmlWebpackExternalsPlugin #hwp | ||
|
||
Test case for issue #97 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('ok'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var select = require('soupselect').select; | ||
var expect = require('expect'); | ||
var htmlparser = require('htmlparser'); | ||
var fs = require('fs'); | ||
|
||
module.exports.check = function check(stats) { | ||
var jsIntegrity; | ||
|
||
expect(stats.compilation.warnings).toEqual([]); | ||
jsIntegrity = stats.compilation.assets['bundle.js'].integrity; | ||
expect(jsIntegrity).toMatch(/^sha/); | ||
|
||
return new Promise((resolve, reject) => { | ||
var handler = new htmlparser.DefaultHandler(function htmlparserCallback( | ||
error, | ||
dom | ||
) { | ||
var scripts; | ||
var i; | ||
|
||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
scripts = select(dom, 'script'); | ||
expect(scripts.length).toEqual(2); | ||
for (i = 0; i < scripts.length; i += 1) { | ||
expect(scripts[0].attribs.crossorigin).toEqual('anonymous'); | ||
expect(scripts[0].attribs.integrity).toBeTruthy(); | ||
} | ||
|
||
resolve(); | ||
}); | ||
new htmlparser.Parser(handler).parseComplete( | ||
fs.readFileSync('./dist/index.html', 'utf-8') | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var SriPlugin = require('webpack-subresource-integrity'); | ||
var HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
var HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin'); | ||
|
||
module.exports = { | ||
entry: './index.js', | ||
output: { | ||
filename: 'bundle.js', | ||
publicPath: '/', | ||
crossOriginLoading: 'anonymous' | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin(), | ||
new HtmlWebpackExternalsPlugin({ | ||
externals: [ | ||
{ | ||
module: 'jquery', | ||
entry: { | ||
path: 'https://code.jquery.com/jquery-3.2.1.js', | ||
attributes: { | ||
integrity: 'sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=', | ||
crossorigin: 'anonymous' | ||
} | ||
}, | ||
global: 'jQuery' | ||
} | ||
] | ||
}), | ||
new SriPlugin({ hashFuncNames: ['sha256', 'sha384'] }) | ||
] | ||
}; |