QR-Code-generator
QR-Code-generator copied to clipboard
Provide TypeScript build instructions (for Windows)
Please add instructions to compile the typescripts on Windows (10):
-
Install node.js https://nodejs.org/en/download/
-
open CMD/powershell
-
Install typescript: https://www.typescriptlang.org/#installation
npm install -g typescript -
install dependency
npm install @types/node -
[add to environment variables: https://stackoverflow.com/questions/36753867/running-tsc-from-the-windows-command-line or invoke via
npx tsc(not tested)] -
compile (as in
build.sh):tsc.cmd --strict --lib DOM,DOM.Iterable,ES6 --target ES6 qrcodegen.ts qrcodegen-input-demo.tstsc.cmd --strict --lib DOM,DOM.Iterable,ES6 --target ES6 qrcodegen.ts qrcodegen-output-demo.tstsc.cmd --strict --target ES2017 --outFile qrcodegen-worker.js qrcodegen.ts qrcodegen-worker.ts
qrcodegen.js is 48 kB.
Minify (default options, I know nothing about these tools):
npm install terser -g
terser.cmd qrcodegen.js --compress --mangle -o qrcodegen.min.js
reduces it to 12 kB, and the "input" demo works with default settings (others not tested). File attached (no warranty).
Except for the installation of nodejs, this probably could be done with a batch file.
The demos:
- "input" is like https://www.nayuki.io/page/qr-code-generator-library
- "output" generates a set of codes
Fantastic project, thanks! I'll try the Python version next.
Thanks for the detailed notes! I'll keep this in mind when I review my documentation.
It would also be great if the transpiled JS version was available in the releases tab here on GitHub, containing a minified and a non-minified version for easier access.
@Connum Thanks for the suggestion! I started making use of GitHub's releases feature, and added compiled JavaScript files. https://github.com/nayuki/QR-Code-generator/releases/tag/v1.6.0
@Connum Thanks for the suggestion! I started making use of GitHub's releases feature, and added compiled JavaScript files. https://github.com/nayuki/QR-Code-generator/releases/tag/v1.6.0
This is great, thanks for the super-quick reaction!
any idea how to generate a es6 module from the tsc?
As it is if you use
tsc.cmd --strict --lib DOM,DOM.Iterable,ES6 --target ES6 qrcodegen.ts
I don't get an es6 module. (there are no exports in the output)
If add
tsc.cmd --strict --lib DOM,DOM.Iterable,ES6 --module es2020 --target ES6 qrcodegen.ts
no change (still no exports). The files exported here (https://github.com/nayuki/QR-Code-generator/releases/tag/v1.6.0) are not es6 modules (they don't export anything)
Reading up on typescript namespaces they sound almost like a deprecated feature, designed before es6 modules. With es6 modules there's no need for namespaces because things are imported into module local variables.
Is there a way to get an es6 module from this code or do I have to modify the code? Should I post a PR?
Here's an es6 module version (if there's a better way would love to know)
https://github.com/greggman/QR-Code-generator/releases/tag/es6-module
Here's the code
https://github.com/greggman/QR-Code-generator/commit/a7b518e650faad081dccba24cd5a5be109771a6c
@greggman awesome! Any chance for a react-native example?
This is how I'm 1. building the Javascript file, 2. minifying using esbuild and 3. Adding UMD module support (one liner):
tsc --strict --lib DOM,DOM.Iterable,ES6 --target ES6 1.8.0/ts/qrcodegen.ts --outFile 1.8.0/qrgen.js
esbuild 1.8.0/qrgen.js --minify --outfile=1.8.0/qrgen.min.js && cat module_append.txt >> 1.8.0/qrgen.min.js
Edit: See also: https://github.com/nayuki/QR-Code-generator/pull/159 which is simply this line:
tsc --strict --lib DOM,DOM.Iterable,ES6 --target ES6 *.ts