anu-verzum 1.11.0 → 1.13.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
@@ -17,22 +17,85 @@ npm install anu-verzum
17
17
 
18
18
  <h3>Babel setup</h3>
19
19
 
20
- The package ships with a Babel preset that configures JSX for you.
21
- Add it to your project's <code>babel.config.json</code>:
20
+ Create a `babel.config.json` in your project root:
22
21
 
23
22
  ```json
24
23
  {
25
- "presets": ["anu-verzum/babel-preset"]
24
+ "presets": [
25
+ "anu-verzum/babel-preset",
26
+ ["@babel/preset-env", { "targets": "last 2 Chrome versions" }]
27
+ ]
26
28
  }
27
29
  ```
28
30
 
29
- This preset transforms JSX to <code>Anu.createElement()</code> calls automatically,
30
- including the <code>&lt;&gt;...&lt;/&gt;</code> fragment shorthand (mapped to <code>Anu.Fragment</code>).
31
+ `anu-verzum/babel-preset` handles two things automatically:
32
+
33
+ - Transforms JSX to `Anu.createElement()` calls, including the `<>...</>` fragment shorthand (mapped to `Anu.Fragment`).
34
+ - Strips TypeScript syntax via `@babel/plugin-transform-typescript` with `jsxPragma: 'Anu'` pre-configured, so the `Anu` import is never incorrectly elided — even in files that only use host elements like `<div>` or `<span>`.
35
+
36
+ Because the preset handles TypeScript stripping itself, **do not** add `@babel/preset-typescript` separately — running both would transform TypeScript twice and cause errors.
37
+
38
+ <h3>Webpack setup</h3>
39
+
40
+ Install the required build dependencies:
41
+
42
+ ```bash
43
+ npm install --save-dev webpack webpack-cli webpack-dev-server html-webpack-plugin babel-loader @babel/core @babel/preset-env
44
+ ```
45
+
46
+ Create (or update) `webpack.config.js`:
47
+
48
+ ```js
49
+ const path = require('path');
50
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
51
+
52
+ module.exports = {
53
+ mode: 'development',
54
+ entry: './src/index.tsx', // use index.js for JavaScript-only projects
55
+ output: {
56
+ path: path.resolve(__dirname, 'dist'),
57
+ filename: 'bundle.js',
58
+ publicPath: '/'
59
+ },
60
+ module: {
61
+ rules: [
62
+ {
63
+ test: /\.[jt]sx?$/, // use /\.jsx?$/ for JavaScript-only projects
64
+ exclude: /node_modules/,
65
+ use: 'babel-loader'
66
+ }
67
+ ]
68
+ },
69
+ resolve: {
70
+ extensions: ['.js', '.jsx', '.tsx', '.ts']
71
+ },
72
+ plugins: [
73
+ new HtmlWebpackPlugin({ template: './index.html' })
74
+ ],
75
+ devServer: {
76
+ port: 3000,
77
+ historyApiFallback: true,
78
+ open: true
79
+ }
80
+ };
81
+ ```
82
+
83
+ Add scripts to `package.json`:
84
+
85
+ ```json
86
+ {
87
+ "scripts": {
88
+ "start": "webpack serve",
89
+ "build": "webpack --mode production"
90
+ }
91
+ }
92
+ ```
31
93
 
32
94
  <h3>Importing in your files</h3>
33
95
 
34
- Every file that contains JSX must import <code>Anu</code>, because the JSX transform
35
- expands to <code>Anu.createElement(...)</code> calls at compile time:
96
+ Every file that contains JSX should import `Anu`, because the JSX transform expands to
97
+ `Anu.createElement(...)` calls at compile time. The preset keeps this import in scope
98
+ automatically, but it is still required at runtime:
36
99
 
37
100
  ```javascript
38
101
  import Anu from 'anu-verzum';
@@ -46,26 +109,55 @@ Anu.render(<App />, document.getElementById('root'));
46
109
 
47
110
  <h3>TypeScript setup</h3>
48
111
 
49
- The library is written in TypeScript and ships with declaration files (`.d.ts`) out of the box —
50
- no extra `@types` package is needed. The `dist/` directory contains only compiled `.js` files and
51
- `.d.ts` declarations, so the package works correctly under all standard TypeScript `moduleResolution`
52
- modes including `"node"`, `"node16"`, and `"bundler"`.
112
+ The library ships with declaration files (`.d.ts`) out of the box — no `@types` package is needed.
113
+
114
+ Install TypeScript for type checking:
115
+
116
+ ```bash
117
+ npm install --save-dev typescript
118
+ ```
119
+
120
+ > **Note:** `@babel/preset-typescript` is **not** needed — `anu-verzum/babel-preset` already handles TypeScript stripping. Only install `typescript` to get the `tsc` CLI for type checking.
53
121
 
54
- If your project uses TypeScript, add the following to your `tsconfig.json` so the compiler
55
- understands JSX produced by ANUVerzum:
122
+ Create `tsconfig.json`:
56
123
 
57
124
  ```json
58
125
  {
59
126
  "compilerOptions": {
127
+ "target": "ES2017",
128
+ "module": "ESNext",
129
+ "moduleResolution": "bundler",
60
130
  "jsx": "react",
61
131
  "jsxFactory": "Anu.createElement",
62
- "jsxFragmentFactory": "Anu.Fragment"
63
- }
132
+ "jsxFragmentFactory": "Anu.Fragment",
133
+ "strict": true,
134
+ "noEmit": true,
135
+ "skipLibCheck": true,
136
+ "esModuleInterop": true
137
+ },
138
+ "include": ["src"]
64
139
  }
65
140
  ```
66
141
 
67
- Every JSX file must still import `Anu` so that `Anu.createElement` is in scope at runtime (same
68
- as the plain JavaScript case).
142
+ | Option | Value | Reason |
143
+ |--------|-------|--------|
144
+ | `jsx` | `"react"` | Enables JSX type-checking with a custom factory |
145
+ | `jsxFactory` | `"Anu.createElement"` | Matches ANUVerzum's JSX transform |
146
+ | `jsxFragmentFactory` | `"Anu.Fragment"` | Matches ANUVerzum's fragment syntax |
147
+ | `noEmit` | `true` | Type checking only — Babel handles compilation |
148
+ | `skipLibCheck` | `true` | Skips type checking inside `node_modules` |
149
+ | `moduleResolution` | `"bundler"` | Correct setting for Webpack/Babel projects |
150
+
151
+ #### Build pipeline
152
+
153
+ Compilation and type checking are intentionally separate:
154
+
155
+ ```bash
156
+ npm start # dev server — Babel compiles, always succeeds
157
+ npx tsc --noEmit # type check only — surfaces type errors
158
+ ```
159
+
160
+ Because compilation goes through Babel, `npm start` and `npm run build` succeed regardless of type errors. Run `npx tsc --noEmit` during development to catch type issues without blocking the build.
69
161
 
70
162
  #### Typed class components
71
163
 
package/babel-preset.js CHANGED
@@ -7,6 +7,13 @@ module.exports = function () {
7
7
  pragma: 'Anu.createElement',
8
8
  pragmaFrag: 'Anu.Fragment'
9
9
  }
10
+ ],
11
+ [
12
+ require('@babel/plugin-transform-typescript'),
13
+ {
14
+ isTSX: true,
15
+ jsxPragma: 'Anu'
16
+ }
10
17
  ]
11
18
  ]
12
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anu-verzum",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "A \"React-like\" UI library that supports JSX syntax, Redux-like state management, array-rendering, i18n, routing and many more.",
5
5
  "keywords": [
6
6
  "anu-verzum",
@@ -38,7 +38,8 @@
38
38
  "test": "echo \"Error: no test specified\" && exit 1"
39
39
  },
40
40
  "dependencies": {
41
- "@babel/plugin-transform-react-jsx": "^7.21.0"
41
+ "@babel/plugin-transform-react-jsx": "^7.21.0",
42
+ "@babel/plugin-transform-typescript": "^7.28.6"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@babel/cli": "^7.21.0",