Bundle using Rollup + Babel + Terser
This commit is contained in:
parent
cb7865b9ee
commit
9e702a1141
6 changed files with 1332 additions and 70 deletions
|
@ -104,7 +104,7 @@ QRCode.toCanvas(canvas, 'sample text', function (error) {
|
||||||
```html
|
```html
|
||||||
<canvas id="canvas"></canvas>
|
<canvas id="canvas"></canvas>
|
||||||
|
|
||||||
<script src="/build/qrcode.min.js"></script>
|
<script src="/build/qrcode.js"></script>
|
||||||
<script>
|
<script>
|
||||||
QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {
|
QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {
|
||||||
if (error) console.error(error)
|
if (error) console.error(error)
|
||||||
|
@ -113,7 +113,9 @@ QRCode.toCanvas(canvas, 'sample text', function (error) {
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
If you install through `npm`, precompiled files will be available in `node_modules/qrcode/build/` folder.<br>
|
If you install through `npm`, precompiled files will be available in `node_modules/qrcode/build/` folder.
|
||||||
|
|
||||||
|
The precompiled bundle have support for [Internet Explorer 10+, Safari 5.1+, and all evergreen browsers](https://browserl.ist/?q=defaults%2C+IE+%3E%3D+10%2C+Safari+%3E%3D+5.1).
|
||||||
|
|
||||||
### NodeJS
|
### NodeJS
|
||||||
Require the module `qrcode`
|
Require the module `qrcode`
|
||||||
|
@ -347,7 +349,7 @@ QRCode.toFile(
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript users: if you are using [@types/qrcode](https://www.npmjs.com/package/@types/qrcode), you will need to add a `// @ts-ignore` above the data segment because it expects `data: string`.
|
TypeScript users: if you are using [@types/qrcode](https://www.npmjs.com/package/@types/qrcode), you will need to add a `// @ts-ignore` above the data segment because it expects `data: string`.
|
||||||
|
|
||||||
## Multibyte characters
|
## Multibyte characters
|
||||||
Support for multibyte characters isn't present in the initial QR Code standard, but is possible to encode UTF-8 characters in Byte mode.
|
Support for multibyte characters isn't present in the initial QR Code standard, but is possible to encode UTF-8 characters in Byte mode.
|
||||||
|
|
52
build.js
52
build.js
|
@ -1,52 +0,0 @@
|
||||||
const childProcess = require('child_process')
|
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
require('colors')
|
|
||||||
|
|
||||||
function createFolder (folderPath) {
|
|
||||||
console.log('*'.green + ' creating folder: '.grey + folderPath.white)
|
|
||||||
|
|
||||||
fs.mkdirSync(folderPath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
function bundle (inputFile, exportName, outputFile, onDone) {
|
|
||||||
console.log('*'.green + ' bundling: '.grey + inputFile.white + ' -> '.grey + outputFile.white)
|
|
||||||
|
|
||||||
const { status, stderr } = childProcess.spawnSync('node', [
|
|
||||||
'node_modules/.bin/browserify',
|
|
||||||
inputFile,
|
|
||||||
'-s', exportName,
|
|
||||||
'-d',
|
|
||||||
'-o', outputFile
|
|
||||||
])
|
|
||||||
|
|
||||||
if (status !== 0) {
|
|
||||||
console.error(stderr.toString())
|
|
||||||
process.exit(status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function minify (inputFile, outputFile) {
|
|
||||||
console.log('*'.green + ' minifying: '.grey + inputFile.white + ' -> '.grey + outputFile.white)
|
|
||||||
|
|
||||||
const { status, stderr } = childProcess.spawnSync('node', [
|
|
||||||
'node_modules/.bin/uglifyjs',
|
|
||||||
'--compress', '--mangle',
|
|
||||||
'--output', outputFile,
|
|
||||||
'--source-map', `url='${path.basename(outputFile)}.map'`,
|
|
||||||
'--', inputFile
|
|
||||||
])
|
|
||||||
|
|
||||||
if (status !== 0) {
|
|
||||||
console.error(stderr.toString())
|
|
||||||
process.exit(status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createFolder('./build')
|
|
||||||
bundle('lib/index.js', 'QRCode', 'build/qrcode.js')
|
|
||||||
bundle('helper/to-sjis.js', 'QRCode.toSJIS', 'build/qrcode.tosjis.js')
|
|
||||||
minify('build/qrcode.js', 'build/qrcode.min.js')
|
|
||||||
minify('build/qrcode.tosjis.js', 'build/qrcode.tosjis.min.js')
|
|
||||||
console.log('\nBuild complete =)\n'.green)
|
|
2
helper/to-sjis-browser.js
Normal file
2
helper/to-sjis-browser.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/* global QRCode */
|
||||||
|
QRCode.toSJIS = require('./to-sjis')
|
1311
package-lock.json
generated
1311
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -30,7 +30,7 @@
|
||||||
"lint": "standard",
|
"lint": "standard",
|
||||||
"pretest": "npm run lint",
|
"pretest": "npm run lint",
|
||||||
"test": "node --throw-deprecation test.js",
|
"test": "node --throw-deprecation test.js",
|
||||||
"build": "node build.js",
|
"build": "rollup -c",
|
||||||
"prepublish": "npm run build",
|
"prepublish": "npm run build",
|
||||||
"browser": "node examples/clientsideserver.js"
|
"browser": "node examples/clientsideserver.js"
|
||||||
},
|
},
|
||||||
|
@ -41,16 +41,22 @@
|
||||||
"dijkstrajs": "^1.0.1",
|
"dijkstrajs": "^1.0.1",
|
||||||
"encode-utf8": "^1.0.3",
|
"encode-utf8": "^1.0.3",
|
||||||
"pngjs": "^5.0.0",
|
"pngjs": "^5.0.0",
|
||||||
"uglify-js": "^3.9.1",
|
|
||||||
"yargs": "^15.3.1"
|
"yargs": "^15.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.9.0",
|
||||||
|
"@babel/preset-env": "^7.9.5",
|
||||||
|
"@rollup/plugin-commonjs": "^11.1.0",
|
||||||
|
"@rollup/plugin-node-resolve": "^7.1.3",
|
||||||
"browserify": "^16.5.1",
|
"browserify": "^16.5.1",
|
||||||
"canvas": "^2.6.1",
|
"canvas": "^2.6.1",
|
||||||
"canvasutil": "0.0.4",
|
"canvasutil": "0.0.4",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"htmlparser2": "^4.1.0",
|
"htmlparser2": "^4.1.0",
|
||||||
|
"rollup": "^2.6.1",
|
||||||
|
"rollup-plugin-babel": "^4.4.0",
|
||||||
|
"rollup-plugin-terser": "^5.3.0",
|
||||||
"sinon": "^9.0.2",
|
"sinon": "^9.0.2",
|
||||||
"standard": "^14.3.3",
|
"standard": "^14.3.3",
|
||||||
"tap": "^14.10.7"
|
"tap": "^14.10.7"
|
||||||
|
|
19
rollup.config.js
Normal file
19
rollup.config.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import babel from 'rollup-plugin-babel'
|
||||||
|
import { terser } from 'rollup-plugin-terser'
|
||||||
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
|
import resolve from '@rollup/plugin-node-resolve'
|
||||||
|
|
||||||
|
const babelConfig = {
|
||||||
|
babelrc: false,
|
||||||
|
presets: [['@babel/preset-env', { targets: 'defaults, IE >= 10, Safari >= 5.1' }]]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [{
|
||||||
|
input: 'lib/browser.js',
|
||||||
|
output: { file: 'build/qrcode.js', format: 'iife', name: 'QRCode', exports: 'named' },
|
||||||
|
plugins: [commonjs(), resolve(), babel(babelConfig), terser()]
|
||||||
|
}, {
|
||||||
|
input: 'helper/to-sjis-browser.js',
|
||||||
|
output: { file: 'build/qrcode.tosjis.js', format: 'iife', exports: 'none' },
|
||||||
|
plugins: [commonjs(), resolve(), babel(babelConfig), terser()]
|
||||||
|
}]
|
Loading…
Reference in a new issue