Skip to content

Commit

Permalink
Ensure we work with HtmlWebpackExternalsPlugin
Browse files Browse the repository at this point in the history
Test case for #97
  • Loading branch information
jscheid committed Dec 10, 2018
1 parent 098f68c commit dfb3123
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/hwp-externals/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# HtmlWebpackExternalsPlugin #hwp

Test case for issue #97
1 change: 1 addition & 0 deletions examples/hwp-externals/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('ok');
38 changes: 38 additions & 0 deletions examples/hwp-externals/test.js
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')
);
});
};
31 changes: 31 additions & 0 deletions examples/hwp-externals/webpack.config.js
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'] })
]
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"file-loader": "^1.1.0",
"get-port": "^3.2.0",
"glob": "^7.1.1",
"html-webpack-externals-plugin": "^3.8.0",
"html-webpack-plugin": "^2.21.0",
"htmlparser": "^1.7.7",
"http-shutdown": "^1.2.0",
Expand Down

0 comments on commit dfb3123

Please sign in to comment.