Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't warn for electron-renderer target #136

Merged
merged 1 commit into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/electron-renderer/README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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