Skip to content

Commit

Permalink
Merge pull request #136 from waysact/134-electron-renderer-warning
Browse files Browse the repository at this point in the history
Don't warn for electron-renderer target
  • Loading branch information
jscheid committed Nov 5, 2020
2 parents ed3c8cd + b51b928 commit 8c5509e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/electron-renderer/README.md
@@ -0,0 +1,3 @@
# Electron Renderer target

Ensure the plugin doesn't warn for electron-renderer targets.
Empty file.
13 changes: 13 additions & 0 deletions examples/electron-renderer/test.js
@@ -0,0 +1,13 @@
var expect = require('expect');
var webpackVersion = Number(
require('webpack/package.json').version.split('.')[0]
);

module.exports.skip = function skip() {
return webpackVersion < 5;
};

module.exports.check = function check(stats) {
expect(stats.compilation.errors).toEqual([]);
expect(stats.compilation.warnings).toEqual([]);
};
19 changes: 19 additions & 0 deletions examples/electron-renderer/webpack.config.js
@@ -0,0 +1,19 @@
var SriPlugin = require('webpack-subresource-integrity');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: {
index: './index.js'
},
target: 'electron-renderer',
output: {
crossOriginLoading: 'anonymous'
},
plugins: [
new SriPlugin({
hashFuncNames: ['sha256', 'sha384'],
enabled: true
}),
new HtmlWebpackPlugin()
]
};
8 changes: 7 additions & 1 deletion jmtp.js
Expand Up @@ -76,7 +76,13 @@ WebIntegrityJsonpMainTemplatePlugin.prototype.apply = function apply(
var linkPreloadPlugin = this.addAttribute.bind(this, mainTemplate, "link");
var addSriHashes = this.addSriHashes.bind(this, mainTemplate);

if (this.compilation.compiler.options.target !== 'web') {
if (
this.compilation.outputOptions.chunkLoading
? ['require', 'async-node'].includes(
this.compilation.outputOptions.chunkLoading
)
: this.compilation.compiler.options.target !== 'web'
) {
this.sriPlugin.warnOnce(
this.compilation,
'This plugin is not useful for non-web targets.'
Expand Down

0 comments on commit 8c5509e

Please sign in to comment.