Skip to content

Commit

Permalink
chore(webapps): fix charset of scripts (camunda#3415)
Browse files Browse the repository at this point in the history
related to camunda#3400
  • Loading branch information
tasso94 authored May 17, 2023
1 parent b4d5df9 commit 3ea7965
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
17 changes: 0 additions & 17 deletions webapps/frontend/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ const webpack = require('webpack');

const {version} = require(path.resolve(__dirname, './package.json'));

class HtmlNoncePlugin {
apply(compiler) {
compiler.hooks.compilation.tap(HtmlNoncePlugin.name, compilation => {
HtmlWebPackPlugin.getHooks(compilation).alterAssetTags.tap(
HtmlNoncePlugin.name,
config => {
config.assetTags.scripts.forEach(script => {
script.attributes['$CSP_NONCE'] = true;
});
return config;
}
);
});
}
}

module.exports = {
entry: {
/* Cockpit */
Expand Down Expand Up @@ -203,7 +187,6 @@ module.exports = {
favicon: path.resolve(__dirname, 'ui/common/images/favicon.ico'),
publicPath: '$APP_ROOT'
}),
new HtmlNoncePlugin(),
new MiniCssExtractPlugin({
// both options are optional, similar to the same options in webpackOptions.output
filename: `[name].css?bust=${version}`,
Expand Down
22 changes: 20 additions & 2 deletions webapps/frontend/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,29 @@ const commonConfig = require(path.resolve(__dirname, './webpack.common.js'));

const {merge} = require('webpack-merge');
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const fs = require('fs');

class HtmlAdditionalAttributesPlugin {
apply(compiler) {
compiler.hooks.compilation.tap(HtmlAdditionalAttributesPlugin.name, compilation => {
HtmlWebPackPlugin.getHooks(compilation).alterAssetTags.tap(
HtmlAdditionalAttributesPlugin.name,
config => {
config.assetTags.scripts.forEach(script => {
script.attributes['$CSP_NONCE'] = true;
script.attributes.charset = 'UTF-8';
});
return config;
}
);
});
}
}

module.exports = () => {
const productionConfig = {
output: {
//publicPath: '',
clean: true
},
module: {
Expand All @@ -51,7 +68,8 @@ module.exports = () => {
}),
new webpack.ProvidePlugin({
DEV_MODE: false
})
}),
new HtmlAdditionalAttributesPlugin()
],
optimization: {
minimize: true,
Expand Down

0 comments on commit 3ea7965

Please sign in to comment.