lilact 0.8.4 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,16 +6,24 @@
6
6
 
7
7
  ---
8
8
 
9
- [Docs on GitHub Pages](https://arashkazemi.github.io/lilact/) — [Demos on GitHub Pages](https://arashkazemi.github.io/lilact/static)
10
-
11
- [Lilact repo on GitHub](https://github.com/arashkazemi/lilact) — [Lilact on npm](https://www.npmjs.com/package/lilact)
12
-
13
- [Lilact/Node/Express Demo Project](https://github.com/arashkazemi/lilact-express) — [Lilact/PHP Demo Project](https://github.com/arashkazemi/lilact-php-demo) — [Lilact/Python Demo Project](https://github.com/arashkazemi/lilact-python-demo)
9
+ [Docs on GitHub Pages](https://arashkazemi.github.io/lilact/)
10
+ ||
11
+ [Demos on GitHub Pages](https://arashkazemi.github.io/lilact/static)
12
+ ||
13
+ [Official Repository](https://github.com/arashkazemi/lilact)
14
+ ||
15
+ [npm Package](https://www.npmjs.com/package/lilact)
16
+ ||
17
+ [Lilact/Node/Express Demo](https://github.com/arashkazemi/lilact-express)
18
+ ||
19
+ [Lilact/PHP Demo](https://github.com/arashkazemi/lilact-php-demo)
20
+ ||
21
+ [Lilact/Python Demo](https://github.com/arashkazemi/lilact-python-demo)
14
22
 
15
23
  ---
16
24
 
17
25
  If you find Lilact useful, please consider sponsoring. Your support funds ongoing maintenance, performance improvements, and new features.
18
- [Sponsor me on GitHub](github.com/sponsors/arashkazemi)
26
+ [Sponsor me on GitHub](https://github.com/sponsors/arashkazemi)
19
27
 
20
28
  ---
21
29
 
@@ -76,16 +84,22 @@ A `webpack` based bundler is available in the `bin` directory. It can be used li
76
84
  npx lilact-bundle --entry client/App.jsx --mode production --name bundle.js --out public/dist
77
85
  ```
78
86
 
87
+ If you add a `--watch` argument, the bundler will not exit and keep watching the input file(s),
88
+ and update the bundle if any file is changed.
89
+
79
90
  ---
80
91
 
81
92
  ## Using Lilact Outside Node.js (Browser / Script Tag Integration)
82
93
 
83
94
  `Lilact` runs in the browser, so if you use `Lilact` outside Node, it uses `eval` to run the transpiled scripts, so it cannot use `import`/`export` the same way as a module.
84
95
 
85
- Import the functions using this convention:
96
+ Import the `Lilact` functions using this convention. There is also a `require` function that you can use
97
+ to load other JSX or JS files.
86
98
 
87
99
  ```js
88
- const { useState, useRef, render } = Lilact;
100
+ const { useState, useRef, render, require } = Lilact;
101
+
102
+ const App = require('./App.jsx');
89
103
  ```
90
104
 
91
105
  To export:
package/bin/bundle.cjs CHANGED
@@ -32,18 +32,19 @@
32
32
  const path = require("path");
33
33
  const webpack = require("webpack");
34
34
 
35
-
36
35
  function parseArgs(argv) {
37
- // Simple args:
38
- // bundler --entry ./src/index.js --out ./dist/bundle
39
36
  const args = {};
40
37
  for (let i = 2; i < argv.length; i++) {
41
38
  const k = argv[i];
42
39
  if (!k.startsWith("--")) continue;
43
40
  const key = k.slice(2);
44
- const v = argv[i + 1];
45
- i++;
46
- args[key] = v;
41
+ if(key==='watch') {
42
+ args[key] = true;
43
+ }
44
+ else {
45
+ const v = argv[++i];
46
+ args[key] = v;
47
+ }
47
48
  }
48
49
  return args;
49
50
  }
@@ -52,22 +53,20 @@ async function run() {
52
53
  const args = parseArgs(process.argv);
53
54
 
54
55
  const userProjectRoot = process.cwd(); // MUST be user's project root
55
- const userEntry = args.entry
56
- ? path.resolve(userProjectRoot, args.entry)
57
- : null;
56
+ const userEntry = args.entry ? path.resolve(userProjectRoot, args.entry) : null;
58
57
 
59
58
  if (!userEntry) {
60
- console.error("Usage: lilact-bundler --entry ./path/to/entry.js --mode production --out ./dist/out --name bundle.js");
59
+ console.error(
60
+ "Usage: lilact-bundler --watch --entry ./path/to/entry.js --mode production --out ./dist/out --name bundle.js"
61
+ );
61
62
  process.exit(1);
62
63
  }
63
64
 
64
65
  const name = args.name ?? "bundle.js";
65
66
  const mode = args.mode ?? "production";
67
+ const watch = args?.watch===true ?? false;
66
68
 
67
- // Locate lilact root reliably (where this CLI is installed)
68
69
  const lilactRoot = path.dirname(require.resolve("lilact/package.json"));
69
-
70
- // Load config factory from your package
71
70
  const configFactoryPath = path.join(lilactRoot, "webpack.config.factory.cjs");
72
71
  const configFactory = require(configFactoryPath);
73
72
 
@@ -75,44 +74,54 @@ async function run() {
75
74
  ? path.resolve(userProjectRoot, args.out)
76
75
  : path.resolve(userProjectRoot, "dist");
77
76
 
78
- // Build config using a factory, then override resolution for user's project
79
77
  const baseConfig = configFactory({
80
78
  entry: userEntry,
81
79
  outputPath: userOutDir,
82
80
  userProjectRoot,
83
- mode, name
81
+ mode,
82
+ name
84
83
  });
85
84
 
86
85
  // ---- Critical: ensure resolution happens from user's project ----
87
86
  baseConfig.context = userProjectRoot;
88
87
  baseConfig.resolve = baseConfig.resolve || {};
89
- baseConfig.resolve.modules = [
90
- path.join(userProjectRoot, "node_modules"),
91
- "node_modules"
92
- ];
88
+ baseConfig.resolve.modules = [path.join(userProjectRoot, "node_modules"), "node_modules"];
93
89
 
94
90
  const compiler = webpack(baseConfig);
95
91
 
96
- compiler.run((err, stats) => {
97
- // webpack keeps resources; close when available
98
- compiler.close(() => {});
99
-
100
- if (err) {
101
- console.error(err);
102
- process.exit(1);
103
- }
104
-
105
- if (stats?.hasErrors?.()) {
106
- console.error(stats.toString("errors-only"));
107
- process.exit(1);
92
+ const watching = compiler.watch(
93
+ {
94
+ // You can tweak these; leaving as defaults usually works.
95
+ // aggregateTimeout: 300,
96
+ // poll: 1000
97
+ },
98
+ (err, stats) => {
99
+ if (err) {
100
+ console.error(err);
101
+ return; // keep watching
102
+ }
103
+
104
+ if (stats?.hasErrors?.()) {
105
+ console.error(stats.toString("errors-only"));
106
+ return; // keep watching
107
+ }
108
+
109
+ console.log(
110
+ stats?.toString?.({
111
+ colors: true,
112
+ chunks: false
113
+ }) || "Build finished."
114
+ );
115
+
116
+ if(!watch) process.exit(1);
108
117
  }
118
+ );
109
119
 
110
- console.log(
111
- stats?.toString?.({
112
- colors: true,
113
- chunks: false
114
- }) || "Build finished."
115
- );
120
+ process.on("SIGINT", () => {
121
+ watching.close(() => process.exit(0));
122
+ });
123
+ process.on("SIGTERM", () => {
124
+ watching.close(() => process.exit(0));
116
125
  });
117
126
  }
118
127
 
@@ -8521,7 +8521,7 @@ var jsx = __webpack_require__(207);
8521
8521
  const lilact_Lilact =
8522
8522
  {
8523
8523
 
8524
- VERSION: "beta.8",
8524
+ VERSION: "beta.9",
8525
8525
 
8526
8526
  // Configuration
8527
8527