A way to transform goog module to esm by ast.
- install it
npm i goog2esm -g
- enter your project waiting for transform
- create config file (goog2esm.config.js) like this
module.exports = {
entry: 'Blockly',
pendingDirs: ['src'],
}
Name | Description |
---|---|
entry | your goog module entry variable(required) |
pendingDirs | Folders to convert(optional) |
- exec command,your goog module will transfrom to esm
goog2esm
- Get all
goog.provide
and generate Map file of namespace and filepath used to calculate import paths. - To avoid circular dependencies, create a transfer file(
_transfer_.js
) to declare the entry variable and import this file into all files to enhance entry variable. - Replace
goog.require
withimport
.The relative path of the file here needs to be calculated. - If goog closure-library is used in the file, import the goog-lib.js I prepared.
- Record the existing namespace, and new declaration will be created for those that do not. as beflow, we need declare
Test.B = {}
goog.provide('Test.B');
Test.B.a = '123';
- Files not referenced from the entry point need to be imported additionally.They are will in
_quote_.js
-
scratch-blocks-esm
use http-server to open test/vertical_playground.html