Skip to content

Commit c369dd2

Browse files
committed
bundling
1 parent 6e551a1 commit c369dd2

20 files changed

Lines changed: 2561 additions & 5375 deletions

.babelrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

.eslintrc.json

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
{
2-
"rules": {
2+
"rules": {
33
"dot-notation": [2],
4-
"indent": [2, "tab", {
4+
"indent": [
5+
2,
6+
"tab",
7+
{
58
"SwitchCase": 1,
69
"ObjectExpression": "first"
710
}
8-
],
9-
"quotes": [2, "single"],
10-
"linebreak-style": [2, "unix"],
11+
],
12+
"quotes": [2, "single"],
13+
"linebreak-style": [2, "unix"],
1114
"no-console": [2, { "allow": ["warn", "error"] }],
12-
"no-eq-null":[2],
13-
"no-eval":[2],
14-
"no-implied-eval":[2],
15+
"no-eq-null": [2],
16+
"no-eval": [2],
17+
"no-implied-eval": [2],
1518
"no-redeclare": [2, { "builtinGlobals": true }],
1619
"one-var": [2, "never"],
17-
"prefer-const":[2],
18-
"semi": [2, "always"],
19-
"keyword-spacing":[2, {
20+
"prefer-const": [2],
21+
"semi": [2, "always"],
22+
"keyword-spacing": [
23+
2,
24+
{
2025
"before": true,
2126
"after": true,
2227
"overrides": {
2328
"if": {
2429
"before": false
25-
},
30+
},
2631
"for": {
2732
"before": false
2833
},
@@ -32,24 +37,18 @@
3237
}
3338
}
3439
],
35-
"space-before-blocks":[2, "always"],
40+
"space-before-blocks": [2, "always"],
3641
"space-before-function-paren": [2, "always"],
37-
"strict":[0, "global"],
42+
"strict": [0, "global"],
3843
"no-unused-vars": [1, { "args": "after-used" }]
39-
},
40-
"env": {
41-
"es6": true,
42-
"browser": true
43-
},
44-
"parserOptions": {
45-
"ecmaVersion": 8,
46-
"sourceType": "module"
4744
},
48-
"parser": "@babel/eslint-parser",
45+
"env": {
46+
"es6": true,
47+
"browser": true
48+
},
4949
"parserOptions": {
50-
"babelOptions": {
51-
"configFile": "./.babelrc"
52-
}
50+
"ecmaVersion": 8,
51+
"sourceType": "module"
5352
},
54-
"extends": "eslint:recommended"
55-
}
53+
"extends": "eslint:recommended"
54+
}

build.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// prettier-ignore
2+
const { promises: { readFile } } = require("fs");
3+
const { build, context } = require("esbuild");
4+
const { sassPlugin } = require("esbuild-sass-plugin");
5+
6+
const DEV = process.argv.includes("--dev");
7+
const CSS = process.argv.includes("--css");
8+
9+
/** @type {import('esbuild').BuildOptions} */
10+
const esbuildBase = {
11+
entryPoints: ["./src/index.js"],
12+
format: "esm",
13+
bundle: true,
14+
minify: true,
15+
platform: "browser",
16+
charset: "utf8",
17+
target: ["firefox78", "chrome78", "safari11.1"],
18+
};
19+
20+
/** @type {import('esbuild').Plugin} */
21+
const kayrosFixPlugin = {
22+
name: "kayros-fix-plugin",
23+
setup(build) {
24+
build.onLoad({ filter: /kayros\.min\.css$/ }, async (args) => {
25+
const fileContents = await readFile(args.path, "utf8");
26+
27+
/**
28+
* @aegis-framework/kayros.css contains an invalid css, let's fix that
29+
*/
30+
const modifiedContents = fileContents.replace("*zoom:1", "zoom:1");
31+
32+
return {
33+
contents: modifiedContents,
34+
loader: "css",
35+
};
36+
});
37+
},
38+
};
39+
40+
/** @type {Record<string, Partial<import('esbuild').BuildOptions>>} */
41+
const builds = {
42+
esm: {
43+
format: "esm",
44+
outfile: "./lib/monogatari.module.js",
45+
sourcemap: "linked",
46+
},
47+
cjs: {
48+
format: "cjs",
49+
outfile: "./lib/monogatari.node.js",
50+
sourcemap: "linked",
51+
define: {
52+
"import.meta.url": "location",
53+
},
54+
},
55+
iife: {
56+
format: "iife",
57+
outfile: "./dist/engine/core/monogatari.js",
58+
globalName: "Monogatari",
59+
define: {
60+
"import.meta.url": "location",
61+
},
62+
},
63+
debug: {
64+
entryPoints: ["./debug/index.js"],
65+
format: "iife",
66+
outfile: "./dist/engine/debug/debug.js",
67+
},
68+
css: {
69+
entryPoints: ["./src/index.css"],
70+
outfile: "./dist/engine/core/monogatari.css",
71+
plugins: [kayrosFixPlugin, sassPlugin()],
72+
},
73+
};
74+
75+
async function main() {
76+
if (DEV) {
77+
const ctx = await context({
78+
...esbuildBase,
79+
...builds["iife"],
80+
entryPoints: [!CSS ? "./src/index.js" : "./src/index.css"],
81+
outfile: !CSS
82+
? "./dist/engine/core/monogatari.js"
83+
: "./dist/engine/core/monogatari.css",
84+
plugins: [kayrosFixPlugin, sassPlugin()],
85+
});
86+
87+
await ctx.watch();
88+
89+
if (!CSS) await ctx.serve({ servedir: "./dist", port: 5173 });
90+
} else {
91+
for (const key in builds) {
92+
await build({
93+
...esbuildBase,
94+
...builds[key],
95+
});
96+
}
97+
}
98+
}
99+
100+
main();

dist/engine/core/monogatari.css

Lines changed: 18 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/engine/core/monogatari.js

Lines changed: 629 additions & 271 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/engine/core/monogatari.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/engine/debug/debug.js

Lines changed: 71 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/engine/debug/debug.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/monogatari.module.js

Lines changed: 629 additions & 263 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/monogatari.module.js.map

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)