mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-19 21:14:44 +08:00
We had to disable CSSNano because it was causing broken fonts in release
builds (exact reason TBC). This CL installs the `cssnano-preset-lite`
package which applies only the following optimisations:
1. remove whitespace
2. remove empty rules (e.g. `div{}`).
3. remove comments
This should be far less risky and unlikely to cause unexpected
breakages.
DISABLE_THIRD_PARTY_CHECK=installed & used cssnano-preset-lite in the
same CL.
Bug: 1399763
Change-Id: I7fdd8b70b02a2c1a5e1c71a87c7ba145114e6e4b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4111923
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
// Copyright 2021 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const {writeIfChanged} = require('./ninja/write-if-changed.js');
|
|
const postcss = require('postcss');
|
|
const cssnano = require('cssnano');
|
|
|
|
async function runCSSMinification(input, fileName) {
|
|
// postcss needs to be given a fileName, even though it doesn't read from it nor write to it.
|
|
// So we pass in the correct name, even though it has no impact on the resulting code.
|
|
const result = await postcss([cssnano({preset: require('cssnano-preset-lite')})]).process(input, {from: fileName});
|
|
return result.css;
|
|
}
|
|
|
|
async function codeForFile({fileName, input, isDebug, isLegacy = false, buildTimestamp}) {
|
|
input = input.replace(/\`/g, '\\\'');
|
|
input = input.replace(/\\/g, '\\\\');
|
|
|
|
const stylesheetContents = isDebug ? input : await runCSSMinification(input, fileName);
|
|
|
|
let exportStatement;
|
|
if (isLegacy) {
|
|
exportStatement = `export default {
|
|
cssContent: \`${stylesheetContents}\`
|
|
};`;
|
|
} else {
|
|
exportStatement = `const styles = new CSSStyleSheet();
|
|
styles.replaceSync(
|
|
\`${stylesheetContents}
|
|
/*# sourceURL=${fileName} */
|
|
\`);
|
|
export default styles;`;
|
|
}
|
|
|
|
const newContents = `// Copyright ${
|
|
new Date(Number(buildTimestamp) * 1000).getUTCFullYear()} The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
// IMPORTANT: this file is auto generated. Please do not edit this file.
|
|
/* istanbul ignore file */
|
|
${exportStatement}
|
|
`;
|
|
return newContents;
|
|
}
|
|
|
|
// Exported only so it can be unit tested.
|
|
exports.codeForFile = codeForFile;
|
|
|
|
async function runMain() {
|
|
const [, , buildTimestamp, isDebugString, legacyString, targetName, srcDir, targetGenDir, files] = process.argv;
|
|
|
|
const filenames = files.split(',');
|
|
const configFiles = [];
|
|
const isDebug = isDebugString === 'true';
|
|
const isLegacy = legacyString === 'true';
|
|
|
|
for (const fileName of filenames) {
|
|
const contents = fs.readFileSync(path.join(srcDir, fileName), {encoding: 'utf8', flag: 'r'});
|
|
const newContents = await codeForFile({fileName, isDebug, input: contents, isLegacy, buildTimestamp});
|
|
const generatedFileName = `${fileName}${isLegacy ? '.legacy' : ''}.js`;
|
|
const generatedFileLocation = path.join(targetGenDir, generatedFileName);
|
|
|
|
writeIfChanged(generatedFileLocation, newContents);
|
|
|
|
configFiles.push(`\"${generatedFileName}\"`);
|
|
}
|
|
|
|
writeIfChanged(path.join(targetGenDir, `${targetName}-tsconfig.json`), `{
|
|
"compilerOptions": {
|
|
"composite": true,
|
|
"outDir": "."
|
|
},
|
|
"files": [
|
|
${configFiles.join(',\n ')}
|
|
]
|
|
}
|
|
`);
|
|
}
|
|
|
|
if (require.main === module) {
|
|
runMain();
|
|
}
|