evil-commonjs is a simple commonjs implement.
Copy index.ts
as evil-commonjs/index.ts
or evil-commonjs.ts
into your TypeScript project ( and change tsconfig.json
if necessary ).
and
await window.module.load("aaa/bbb/index.js", ["bbb"]); // aaa depends on bbb.
await window.module.load("aaa/index.js", ["aaa"]);
or
await window.module.sequentialLoad
([
{ path:"aaa/bbb/index.js", mapping:["bbb"] }, // aaa depends on bbb.
{ path:"aaa/index.js", mapping:["aaa"] },
]);
You can now use window.require("aaa")
and import aaa from 'aaa'
!
Specify a relative path from location.href
or a absolute path for first parameter of window.module.load()
.
await window.module.load("aaa/bbb/index.js", ["bbb"]); // aaa depends on bbb.
const aaa = await window.module.load("aaa/index.js");
Like this, you can also get directly from window.module.load()
without using require
.
<script src="https://wraith13.github.io/evil-commonjs/index.js"></script>
<script>
window.module.sequentialLoad
([
{ path:"aaa/bbb/index.js", mapping:["bbb"] }, // aaa depends on bbb.
{ path:"aaa/index.js", mapping:["aaa"] },
]).then
(
map =>
{
var aaa = require("aaa/index.js");
...
}
);
</script>
You can also use like this style.
You can specify console output settings as follows.
<script>
const evilCommonjsConfig =
{
log:
{
config: false,
load: true,
define: true,
results: false,
},
loadingTimeout: 1500,
};
</script>
<script src="https://wraith13.github.io/evil-commonjs/index.js"></script>
All individual settings are optional.
You can also specify console output settings on URL. Note that the arguments here must be valid as JSON.( 🚫 ...?evil-commonjs={loadingTimeout:1500,}
→ ✅ ...?evil-commonjs={"loadingTimeout":1500}
)
https://example.com/your-page-path?evil-commonjs={"log":{"config":false,"load":true,"define":true,"results":false},"loadingTimeout":1500}
requires: Node.js, TypeScript Compiler
tsc -P .
or tsc -P . -w
You can use automatic build. Run Tasks: Allow Automatic Tasks in Folder
command from command palette ( Mac: F1 or Shift+Command+P, Windows and Linux: F1 or Shift+Ctrl+P), and restart VS Code.