Skip to content

Commit 89e2feb

Browse files
authored
Merge pull request #1073 from gaearon/auto-disable
Auto-disable RHL in unsupported environments
2 parents d6ca2bb + af2376e commit 89e2feb

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Webpack App</title>
6+
<meta http-equiv="Content-Security-Policy" content="default-src http:">
7+
</head>
8+
<body>
9+
</body>
10+
</html>

examples/styled-components/webpack.config.babel.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,11 @@ module.exports = {
2727
),
2828
},
2929
},
30-
plugins: [new HtmlWebpackPlugin(), new webpack.NamedModulesPlugin()],
30+
plugins: [
31+
new HtmlWebpackPlugin({
32+
// uncomment this line to test RHL in "secure" env
33+
// template: "index_csp.html",
34+
}),
35+
new webpack.NamedModulesPlugin(),
36+
],
3137
}

index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
'use strict'
22

3-
if (!module.hot || process.env.NODE_ENV === 'production') {
3+
let evalAllowed = false;
4+
try {
5+
eval('evalAllowed = true');
6+
} catch (e) {
7+
// eval not allowed due to CSP
8+
}
9+
10+
// RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods
11+
const platformSupported = !!Object.setPrototypeOf && evalAllowed;
12+
13+
if (!module.hot || process.env.NODE_ENV === 'production' || !platformSupported) {
14+
if (module.hot) {
15+
// we are not in prod mode, but RHL could not be activated
16+
console.warn('React-Hot-Loaded is not supported in this environment');
17+
}
418
module.exports = require('./dist/react-hot-loader.production.min.js');
519
} else {
620
module.exports = require('./dist/react-hot-loader.development.js');

0 commit comments

Comments
 (0)