Skip to content

Commit e0c225d

Browse files
committed
fix: dont ship source maps for css in prod builds
1 parent 2cfb221 commit e0c225d

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
function cloneStyleTags() {
2-
const linkTags = [];
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export function cloneStyleTags(): Array<HTMLLinkElement | HTMLStyleElement> {
11+
const tags: Array<HTMLLinkElement | HTMLStyleElement> = [];
312

413
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
514
for (const linkTag of document.getElementsByTagName('link')) {
@@ -11,11 +20,23 @@ function cloneStyleTags() {
1120
newLinkTag.setAttribute(attribute.nodeName, attribute.nodeValue);
1221
}
1322

14-
linkTags.push(newLinkTag);
23+
styleTags.push(newLinkTag);
1524
}
1625
}
1726

18-
return linkTags;
19-
}
27+
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
28+
for (const styleTag of document.getElementsByTagName('style')) {
29+
const newStyleTag = document.createElement('style');
30+
31+
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
32+
for (const attribute of styleTag.attributes) {
33+
newStyleTag.setAttribute(attribute.nodeName, attribute.nodeValue);
34+
}
2035

21-
export default cloneStyleTags;
36+
newStyleTag.textContent = styleTag.textContent;
37+
38+
tags.push(newStyleTag);
39+
}
40+
41+
return tags;
42+
}

packages/react-devtools-extensions/src/main/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
import {viewAttributeSource} from './sourceSelection';
3434

3535
import {startReactPolling} from './reactPolling';
36-
import cloneStyleTags from './cloneStyleTags';
36+
import {cloneStyleTags} from './cloneStyleTags';
3737
import fetchFileWithCaching from './fetchFileWithCaching';
3838
import injectBackendManager from './injectBackendManager';
3939
import registerEventsLogger from './registerEventsLogger';

packages/react-devtools-extensions/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ module.exports = {
285285
{
286286
loader: 'css-loader',
287287
options: {
288-
sourceMap: true,
288+
sourceMap: __DEV__,
289289
modules: true,
290290
localIdentName: '[local]___[hash:base64:5]',
291291
},

0 commit comments

Comments
 (0)