From 3a12ac0d1c02a073a13c0b84174cc0337f2c3c01 Mon Sep 17 00:00:00 2001 From: Huguenin-Elie Steve Date: Thu, 1 Apr 2021 10:23:50 +0200 Subject: [PATCH] definitive toolchain compilation esm and cjs are produced by tsc rollup build all wasm loaders --- .babelrc.js | 4 ++-- .gitignore | 2 +- .size-snapshot.json | 6 +++--- build/loader-debug.js | 14 ++++++++++++++ build/loader-release.js | 14 ++++++++++++++ package.json | 18 +++++++----------- rollup.config.js | 35 +++++++++++++++++++++++++++-------- 7 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 build/loader-debug.js create mode 100644 build/loader-release.js diff --git a/.babelrc.js b/.babelrc.js index 38fe1a58..9cd650f8 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -1,8 +1,8 @@ module.exports = { - "presets": ["@babel/preset-typescript"], + "presets": ["@babel/preset-env"], "env": { "esm": { - "presets": [["@babel/preset-typescript", { "modules": false }]], + "presets": [["@babel/preset-env", { "modules": false }]], } } }; diff --git a/.gitignore b/.gitignore index e5926b77..31d08d5e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ .DS_Store tmp node_modules -npm-debug.log +*.log package-lock.json yarn.lock dist diff --git a/.size-snapshot.json b/.size-snapshot.json index 6e1b2705..3f9a0929 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -5,8 +5,8 @@ "gzipped": 13273 }, "dist\\gl-matrix-min.js": { - "bundled": 228852, - "minified": 52941, - "gzipped": 13521 + "bundled": 52941, + "minified": 52870, + "gzipped": 13467 } } diff --git a/build/loader-debug.js b/build/loader-debug.js new file mode 100644 index 00000000..fc44ff05 --- /dev/null +++ b/build/loader-debug.js @@ -0,0 +1,14 @@ +import wasm from './untouched.wasm'; + +let modules; + +wasm({ ...imports }).then(({ instance }) => { + modules = instance.exports +}) + +export const { + glMatrix, + mat2, mat2d, mat3, mat4, + quat, quat2, + vec2, vec3, vec4 +} = modules; diff --git a/build/loader-release.js b/build/loader-release.js new file mode 100644 index 00000000..ed55662e --- /dev/null +++ b/build/loader-release.js @@ -0,0 +1,14 @@ +import wasm from './optimized.wasm'; + +let modules; + +wasm({ ...imports }).then(({ instance }) => { + modules = instance.exports +}) + +export const { + glMatrix, + mat2, mat2d, mat3, mat4, + quat, quat2, + vec2, vec3, vec4 +} = modules; diff --git a/package.json b/package.json index 2eb94a53..d594fe90 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,10 @@ "doc": "jsdoc -c jsdoc.config.json", "update-license-version": "node utils/update-license-version.js", "build-umd": "rollup -c", - "build-esm": "cross-env BABEL_ENV=esm babel assembly -d dist/esm", - "build-cjs": "babel assembly -d dist/cjs", + "build-esm": "tsc --module es6 assembly/index.ts --outDir dist/esm", + "build-cjs": "tsc --module commonjs assembly/index.ts -outDir dist/cjs", "build-dts": "tsc --declaration --emitDeclarationOnly --module amd --outFile ./dist/index.d.ts ./assembly/index.ts && node ./utils/bundle-dts.js && tsc --noEmit ./dist/index.d.ts", - "build-portable": "del dist && npm run update-license-version && npm run build-umd && npm run build-esm && npm run build-cjs && npm run build-dts && node ./utils/build.js", - "build": "npm run build-portable && npm run asbuild", + "build": "del dist && npm run update-license-version && npm run asbuild && npm run build-umd && npm run build-esm && npm run build-cjs && npm run build-dts && node ./utils/build.js", "prepare": "npm run build", "asbuild:untouched": "asc assembly/index.ts --target debug", "asbuild:optimized": "asc assembly/index.ts --target release", @@ -43,12 +42,11 @@ }, "devDependencies": { "@assemblyscript/loader": "^0.18.17", - "@babel/cli": "^7.8.4", - "@babel/core": "^7.9.0", - "@babel/preset-env": "^7.9.0", - "@babel/preset-typescript": "^7.13.0", + "@babel/core": "7.9.0", "@babel/register": "^7.9.0", + "@rollup/plugin-replace": "^2.4.2", "@rollup/plugin-typescript": "^8.2.1", + "@rollup/plugin-wasm": "^5.1.2", "assemblyscript": "^0.18.16", "cross-env": "^7.0.2", "del-cli": "^3.0.0", @@ -56,10 +54,8 @@ "mocha": "^7.1.1", "node-libs-browser": "^2.2.1", "rollup": "^2.3.2", - "rollup-plugin-assemblyscript": "^2.0.0", - "rollup-plugin-babel": "^4.4.0", "rollup-plugin-size-snapshot": "^0.11.0", - "rollup-plugin-terser": "^5.3.0", + "rollup-plugin-terser": "5.3.0", "typescript": "^3.8.3" }, "dependencies": {} diff --git a/rollup.config.js b/rollup.config.js index b4ff719f..fd861a63 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,8 @@ -import babel from 'rollup-plugin-babel'; -import { terser } from 'rollup-plugin-terser'; import { sizeSnapshot } from 'rollup-plugin-size-snapshot'; +import { terser } from 'rollup-plugin-terser'; +import replace from '@rollup/plugin-replace'; import typescript from '@rollup/plugin-typescript'; +import wasm from '@rollup/plugin-wasm'; const version = require('./package.json').version; const license = require('./utils/license-template'); @@ -22,26 +23,44 @@ ${license} } export default [ + { + input: './build/loader-debug.js', + output: { file: 'dist/wasm/gl-matrix-loader-debug.js', format: 'umd', name }, + plugins: [ + replace({ preventAssignment: true }), + wasm(), + bannerPlugin + ] + }, + { + input: './build/loader-release.js', + output: { file: 'dist/wasm/gl-matrix-loader-release.js', format: 'umd', name }, + plugins: [ + replace({ preventAssignment: true }), + wasm(), + bannerPlugin + ] + }, { input, output: { file: 'dist/gl-matrix.js', format: 'umd', name }, plugins: [ + replace({ preventAssignment: true }), typescript(), - bannerPlugin, - babel() + bannerPlugin ] }, { input, output: { file: 'dist/gl-matrix-min.js', format: 'umd', name }, plugins: [ + replace({ preventAssignment: true }), typescript(), - bannerPlugin, - babel(), - sizeSnapshot(), terser({ output: { comments: /^!/ } - }) + }), + sizeSnapshot(), + bannerPlugin ] } ];