Skip to content

Commit 97ea03f

Browse files
authored
Merge pull request #17 from piotr-oles/fix/dont-debug-production-build
fix: don't debug production build
2 parents 29a0692 + 3b34dfd commit 97ea03f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ Options passed to the [AssemblyScript compiler](https://www.assemblyscript.org/c
333333

334334
| Name | Type | Description |
335335
|------------------|----------| ----------- |
336-
| `debug` | boolean | Enables debug information in emitted binaries. |
337-
| `optimizeLevel` | number | How much to focus on optimizing code. [0-3] |
338-
| `shrinkLevel` | number | How much to focus on shrinking code size. [0-2] |
336+
| `debug` | boolean | Enables debug information in emitted binaries, enabled by default in webpack development mode. |
337+
| `optimizeLevel` | number | How much to focus on optimizing code, 3 by default. [0-3] |
338+
| `shrinkLevel` | number | How much to focus on shrinking code size, 1 by default. [0-2] |
339339
| `coverage` | boolean | Re-optimizes until no further improvements can be made. |
340-
| `noAssert` | boolean | Replaces assertions with just their value without trapping. |
340+
| `noAssert` | boolean | Replaces assertions with just their value without trapping, enabled by default in webpack production mode. |
341341
| `importMemory` | boolean | Imports the memory provided as 'env.memory'. |
342342
| `noExportMemory` | boolean | Does not export the memory as 'memory'. |
343343
| `initialMemory` | number | Sets the initial memory size in pages. |

src/loader/index.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getOptions, interpolateName, OptionObject } from "loader-utils";
55
import { validate } from "schema-utils";
66
import { Schema } from "schema-utils/declarations/validate";
77
import { createCompilerHost } from "./compiler-host";
8-
import { mapAscOptionsToArgs } from "./options";
8+
import { mapAscOptionsToArgs, Options } from "./options";
99
import { AssemblyScriptError } from "./error";
1010
import schema from "./schema.json";
1111
import { addErrorToModule, addWarningToModule } from "./webpack";
@@ -43,11 +43,15 @@ function loader(this: any, buffer: Buffer) {
4343
...userAscOptions
4444
} = options as LoaderOptions & CompilerOptions;
4545

46-
const ascOptions = {
46+
const ascOptions: Options = {
4747
// default options
4848
// when user imports wasm with webassembly type, it's not possible to pass env
4949
runtime: module.type?.startsWith("webassembly") ? "stub" : "incremental",
5050
exportRuntime: !module.type?.startsWith("webassembly"),
51+
debug: this.mode === "development",
52+
optimizeLevel: 3,
53+
shrinkLevel: 1,
54+
noAssert: this.mode === "production",
5155
// user options
5256
...userAscOptions,
5357
};
@@ -91,6 +95,10 @@ function loader(this: any, buffer: Buffer) {
9195

9296
const host = createCompilerHost(this);
9397

98+
if (shouldGenerateSourceMap) {
99+
ascOptions.sourceMap = true;
100+
}
101+
94102
const args = [
95103
path.basename(this.resourcePath),
96104
"--baseDir",
@@ -99,9 +107,6 @@ function loader(this: any, buffer: Buffer) {
99107
outFileName,
100108
...mapAscOptionsToArgs(ascOptions),
101109
];
102-
if (shouldGenerateSourceMap) {
103-
args.push("--sourceMap", "--debug");
104-
}
105110
if (bind && name.endsWith(".wasm")) {
106111
// add required by as-bind file to compilation
107112
args.unshift(require.resolve("as-bind/lib/assembly/as-bind.ts"));

src/loader/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ function mapAscOptionsToArgs(options: Options): string[] {
2222
return args;
2323
}
2424

25-
export { mapAscOptionsToArgs };
25+
export { mapAscOptionsToArgs, Options };

0 commit comments

Comments
 (0)