Skip to content

Commit 21ef8ad

Browse files
Fixed CSP Strict Style Compatibility
Fixes plotly#2355 Plotly uses inline CSS * Providing switch in build process to enable CSP strict style build * Creating a static CSS file at command line provided path defaulting to build folder with name plot-csp.css
1 parent f3357f5 commit 21ef8ad

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"schema": "node tasks/schema.js",
2929
"stats": "node tasks/stats.js",
3030
"find-strings": "node tasks/find_locale_strings.js",
31-
"preprocess": "node tasks/preprocess.js",
31+
"preprocess": "node tasks/preprocess.js %npm_config_cspNoInlineStyle% %npm_config_pathToCSS%",
3232
"use-draftlogs": "node tasks/use_draftlogs.js",
3333
"empty-draftlogs": "node tasks/empty_draftlogs.js",
3434
"empty-dist": "node tasks/empty_dist.js",

tasks/preprocess.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ function makeBuildCSS() {
2121
}, function(err, result) {
2222
if(err) throw err;
2323

24-
// css to js
25-
pullCSS(String(result.css), constants.pathToCSSBuild);
24+
var cspNoInlineStyle = process.argv[2];
25+
var pathToCSS = process.argv[3] || 'plot-csp.css';
26+
if(cspNoInlineStyle) {
27+
// if csp no inline style then build css file to include at path relative to build folder
28+
fs.writeFile(constants.pathToBuild + pathToCSS, String(result.css), function(err) {
29+
if(err) throw err;
30+
});
31+
} else {
32+
// css to js
33+
pullCSS(String(result.css), constants.pathToCSSBuild);
34+
}
2635
});
2736
}
2837

0 commit comments

Comments
 (0)