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("entrypoint", &self.entrypoint);
build.add_inputs("", inputs!["yarn.lock", ":node_modules", &self.deps]);
build.add_inputs("", inputs!["out/env"]);
let stem = self.output_stem;
let mut outs = vec![format!("{stem}.js")];
outs.extend(self.extra_exts.iter().map(|ext| format!("{stem}.{ext}")));

2
ninja
View File

@ -8,7 +8,7 @@ else
out="$BUILD_ROOT"
fi
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
cargo build -p runner

View File

@ -3,4 +3,4 @@
# The pages can be accessed by, eg surfing to
# 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
const target = ["es6", "chrome77"];
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({
bundle: true,
@ -29,21 +50,12 @@ build({
minify: env.RELEASE && true,
loader: { ".svg": "text" },
preserveSymlinks: true,
sourcemap: false,
sourcemap: sourcemap ? "inline" : false,
plugins: [
sassPlugin({ loadPaths: [".", "node_modules"] }),
sveltePlugin({
compilerOptions: { css: inlineCss },
preprocess: [
typescript({
target,
define: {
"process.browser": "true",
},
tsconfig: "ts/tsconfig.json",
}),
sveltePreprocess({ typescript: false }),
],
preprocess: sveltePlugins,
}),
],
target,

View File

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