mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-29 16:57:00 +08:00
Minify locale JSON files at build time
This CL adds a new build rule "minify_json" that takes a list of JSON files, minifies them, and puts the result into then "gen/" directory. The i18n module uses the new rule to minify the locale JSON, reducing the raw size per locale file 10-15%. R=tvanderlippe@chromium.org Fixed: 1293324 Change-Id: I0aabc5cdea7957334dfe21304e117dc23a563606 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3431345 Reviewed-by: Tim Van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org>
This commit is contained in:
committed by
Devtools-frontend LUCI CQ
parent
fe62fa1968
commit
957496f839
@@ -5,6 +5,7 @@
|
||||
import("../../../scripts/build/ninja/devtools_entrypoint.gni")
|
||||
import("../../../scripts/build/ninja/devtools_module.gni")
|
||||
import("../../../scripts/build/ninja/devtools_pre_built.gni")
|
||||
import("../../../scripts/build/ninja/minify_json.gni")
|
||||
|
||||
devtools_module("i18n") {
|
||||
sources = [
|
||||
@@ -23,7 +24,7 @@ devtools_module("i18n") {
|
||||
|
||||
public_deps = [
|
||||
":i18n_bundled_locales",
|
||||
":i18n_remote_locales",
|
||||
":i18n_locales",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -122,20 +123,26 @@ bundled_devtools_locale_files = [
|
||||
"zh.json",
|
||||
]
|
||||
|
||||
copy_to_gen("i18n_remote_locales") {
|
||||
minify_json("i18n_locales") {
|
||||
sources = []
|
||||
foreach(locale, remote_devtools_locale_files) {
|
||||
foreach(locale,
|
||||
remote_devtools_locale_files + bundled_devtools_locale_files) {
|
||||
sources += [ "locales/$locale" ]
|
||||
}
|
||||
}
|
||||
|
||||
devtools_pre_built("i18n_bundled_locales") {
|
||||
sources = []
|
||||
group("i18n_bundled_locales") {
|
||||
public_deps = [ ":i18n_locales" ]
|
||||
|
||||
data = []
|
||||
|
||||
foreach(locale, bundled_devtools_locale_files) {
|
||||
sources += [ "locales/$locale" ]
|
||||
data += [ "$target_gen_dir/locales/$locale" ]
|
||||
}
|
||||
|
||||
metadata = {
|
||||
grd_files = data
|
||||
}
|
||||
}
|
||||
|
||||
# For locales that are only used by tests, and not in releases.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright 2022 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('./write-if-changed.js');
|
||||
|
||||
const [, , src, dest, files] = process.argv;
|
||||
|
||||
for (const file of files.split(',')) {
|
||||
const srcPath = path.join(src, file);
|
||||
const destPath = path.join(dest, file);
|
||||
|
||||
// Minifying JSON is straight-forward as JSON.stringify omits whitespace.
|
||||
const srcContents = fs.readFileSync(srcPath);
|
||||
const destContents = JSON.stringify(JSON.parse(srcContents));
|
||||
writeIfChanged(destPath, destContents);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
# Copyright 2022 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.
|
||||
|
||||
import("./node.gni")
|
||||
import("./vars.gni")
|
||||
|
||||
template("minify_json") {
|
||||
node_action(target_name) {
|
||||
forward_variables_from(invoker, [ "sources" ])
|
||||
|
||||
script = "scripts/build/ninja/minify-json-files.js"
|
||||
|
||||
_src = rebase_path(".", root_build_dir)
|
||||
_dest = rebase_path(target_gen_dir, root_build_dir)
|
||||
|
||||
args = [
|
||||
_src,
|
||||
_dest,
|
||||
string_join(",", sources),
|
||||
]
|
||||
|
||||
outputs = []
|
||||
foreach(_input, sources) {
|
||||
outputs += [ "$target_gen_dir/$_input" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user