Add env var to enable sourcemaps

They slow down the build, so are not on by default.
This commit is contained in:
Damien Elmes 2022-12-04 11:25:56 +10:00
parent ecfa557043
commit 7f5e3c8106
5 changed files with 27 additions and 13 deletions

View file

@ -150,6 +150,7 @@ impl BuildAction for EsbuildScript<'_> {
build.add_inputs("script", &self.script); build.add_inputs("script", &self.script);
build.add_inputs("entrypoint", &self.entrypoint); build.add_inputs("entrypoint", &self.entrypoint);
build.add_inputs("", inputs!["yarn.lock", ":node_modules", &self.deps]); build.add_inputs("", inputs!["yarn.lock", ":node_modules", &self.deps]);
build.add_inputs("", inputs!["out/env"]);
let stem = self.output_stem; let stem = self.output_stem;
let mut outs = vec![format!("{stem}.js")]; let mut outs = vec![format!("{stem}.js")];
outs.extend(self.extra_exts.iter().map(|ext| format!("{stem}.{ext}"))); outs.extend(self.extra_exts.iter().map(|ext| format!("{stem}.{ext}")));

2
ninja
View file

@ -8,7 +8,7 @@ else
out="$BUILD_ROOT" out="$BUILD_ROOT"
fi fi
export CARGO_TARGET_DIR=$out/rust export CARGO_TARGET_DIR=$out/rust
export RECONFIGURE_KEY="${MAC_X86};" export RECONFIGURE_KEY="${MAC_X86};${SOURCEMAP}"
# separate build+run steps so build env doesn't leak into subprocesses # separate build+run steps so build env doesn't leak into subprocesses
cargo build -p runner cargo build -p runner

View file

@ -3,4 +3,4 @@
# The pages can be accessed by, eg surfing to # The pages can be accessed by, eg surfing to
# http://localhost:40000/_anki/pages/deckconfig.html # http://localhost:40000/_anki/pages/deckconfig.html
QTWEBENGINE_REMOTE_DEBUGGING=8080 ANKI_API_PORT=40000 ./run $* QTWEBENGINE_REMOTE_DEBUGGING=8080 ANKI_API_PORT=40000 SOURCEMAP=1 ./run $*

View file

@ -20,6 +20,27 @@ if (page_html != null) {
// support Qt 5.14 // support Qt 5.14
const target = ["es6", "chrome77"]; const target = ["es6", "chrome77"];
const inlineCss = bundle_css == null; const inlineCss = bundle_css == null;
const sourcemap = env.SOURCEMAP && true;
let sveltePlugins;
if (!sourcemap) {
sveltePlugins = [
// use esbuild for faster typescript transpilation
typescript({
target,
define: {
"process.browser": "true",
},
tsconfig: "ts/tsconfig.json",
}),
sveltePreprocess({ typescript: false }),
];
} else {
sveltePlugins = [
// use tsc for more accurate sourcemaps
sveltePreprocess({ typescript: true, sourceMap: true }),
];
}
build({ build({
bundle: true, bundle: true,
@ -29,21 +50,12 @@ build({
minify: env.RELEASE && true, minify: env.RELEASE && true,
loader: { ".svg": "text" }, loader: { ".svg": "text" },
preserveSymlinks: true, preserveSymlinks: true,
sourcemap: false, sourcemap: sourcemap ? "inline" : false,
plugins: [ plugins: [
sassPlugin({ loadPaths: [".", "node_modules"] }), sassPlugin({ loadPaths: [".", "node_modules"] }),
sveltePlugin({ sveltePlugin({
compilerOptions: { css: inlineCss }, compilerOptions: { css: inlineCss },
preprocess: [ preprocess: sveltePlugins,
typescript({
target,
define: {
"process.browser": "true",
},
tsconfig: "ts/tsconfig.json",
}),
sveltePreprocess({ typescript: false }),
],
}), }),
], ],
target, target,

View file

@ -14,6 +14,7 @@ build({
entryPoints: [entrypoint], entryPoints: [entrypoint],
outfile: bundle_js, outfile: bundle_js,
minify: env.RELEASE && true, minify: env.RELEASE && true,
sourcemap: env.SOURCEMAP ? "inline" : false,
preserveSymlinks: true, preserveSymlinks: true,
target, target,
}).catch(() => process.exit(1)); }).catch(() => process.exit(1));