Conversation
- add `require` field to `build.json` for node_modules deps that are concatenated first - add `libDir` field to `build.json` to treat cases like `metacom/dist` - skip `import` lines alongside with `require` - add test for including required libs from node_modules - changed filename comment to `#region` comment to allow collapse of code region in vscode-like editors metarhia/metautil#311
tshemsedinov
left a comment
There was a problem hiding this comment.
Build steps in short
- npm library build
1.1. Remove require/import of local sub-modules
1.2. Convertmodule.exportsto export
1.3. Concatenate library files but not dependencies - application build
2.1. Add links tonode_modulesfiles from server/static/folder
2.2. Alternatively application can use any bundler to build ours npm files in traditional way
metarhia-build.js
Outdated
| `// Version ${packageJson.version} ${packageName} ${licenseName}\n\n`; | ||
| const requiredLibs = (buildConfig.require || []) | ||
| .map((lib) => { | ||
| const fileName = `./node_modules/${lib}/${lib}.mjs`; |
There was a problem hiding this comment.
Do not build dependencies from node_modules
There was a problem hiding this comment.
I've added iife build mode (separate commit - easy to revert).
This will include deps from node_modules to prepare lib for worker. We will need it for metacom in serviceworker
There was a problem hiding this comment.
I need a time to find better solution
There was a problem hiding this comment.
Left same comment here metarhia/metacom#528 (comment)
As for the iife mode there are not so many options I can think about.
1 - the one used here - include whole lib from deps since metarhia build don't treeshake
2 - use 3d party builder like esbuild rollup rolldown to build iife that includes only required classes/functions
3 - drop service worker support for Firefox and use ESM modules same as in main thread no need in iife.
4 - or make a special iife file for each lib that uses metarhia-build (metautil, probably metaschema, etc.) and force end user to include importScripts('metautil.iife.js') that exposes global metautilIIFE variable to SW context.
There was a problem hiding this comment.
Applied changes - as we discussed in telegram @tshemsedinov
After Firefox fixed bug with service worker imports https://bugzilla.mozilla.org/show_bug.cgi?id=1360870
Changed the builder
- lib mode builds
lib.mjsfile and adds metarhia deps imports likeimport metautil from './metautil.js'-.js - then in app mode symlinks
.mjsas.jsso end user app will fnd correct esm files served from static folder
Rebuild corresponding metacom and matautil PRs
metacom - (to master branch) metarhia/metacom#528
metautil - (to created by you build branch) https://github.com/metarhia/metautil/pull/315/changes
also there is a metachema - (to master) metarhia/metaschema#480
|
I've changed how deps are processed. No need for I've added
Research repo - Slides: |
- process file as a whole instead line by line to simplify multiline import processing
71e0a13 to
4b600f6
Compare
- hide mode executors in modes/index.js - fixed use strict regex - break execution when not from console (e.g. load module by impress)
4b600f6 to
acd25c8
Compare
- user must import deps before module
308833c to
286116e
Compare
modefield tobuild.jsonwithapp,iifeand defaultlibmodeslibDirfield tobuild.jsonto treat cases likemetacom/distimportlines alongside withrequire#regioncomment to allow collapse of code region in vscode-like editorsmetarhia/metautil#311
npm t)npm run fix)