babel-plugin-reactylon 1.0.4 → 1.0.5

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
@@ -1,6 +1,6 @@
1
1
  # Babel Plugin Reactylon
2
2
 
3
- A Babel plugin designed to enable tree shaking in a Reactylon application. It statically analyzes Reactylon JSX elements and automatically manages imports and registrations of the relative Babylon.js classes, ensuring only the necessary parts of the Babylon.js library are included in the final bundle.
3
+ A Babel plugin designed to enable **tree shaking** in a Reactylon application. It statically analyzes Reactylon JSX elements and automatically manages imports and registrations of the relative Babylon.js classes, ensuring only the necessary parts of the Babylon.js library are included in the final bundle.
4
4
 
5
5
  ## Features
6
6
  - Automatic detection of Babylon.js components used in JSX
@@ -11,7 +11,13 @@ A Babel plugin designed to enable tree shaking in a Reactylon application. It st
11
11
 
12
12
  ## Configuration
13
13
 
14
- ### Babel
14
+ To get started, install the plugin using the following command:
15
+
16
+ ```bash
17
+ npm install babel-plugin-reactylon --save-dev
18
+ ```
19
+
20
+ ### Babel (standalone, Next.js or React Native)
15
21
 
16
22
  Add the plugin to your Babel configuration:
17
23
 
@@ -62,6 +68,20 @@ module: {
62
68
  };
63
69
  ```
64
70
 
71
+ ### Vite
72
+ ```js
73
+ // vite.config.js
74
+ export default defineConfig({
75
+ plugins: [
76
+ react({
77
+ babel: {
78
+ plugins: ['babel-plugin-reactylon']
79
+ }
80
+ }),
81
+ ],
82
+ })
83
+ ```
84
+
65
85
  ### Additional configurations
66
86
  Additionally you can manually define extra side effects (see [Babylon.js ES6 support FAQ](https://doc.babylonjs.com/setup/frameworkPackages/es6Support/#faq)) or specify a custom `node_modules` path (useful if you are working with a monorepo setup).
67
87
 
@@ -77,7 +97,7 @@ Additionally you can manually define extra side effects (see [Babylon.js ES6 sup
77
97
  ```
78
98
 
79
99
  ## How it works
80
- The plugin analyzes your JSX code by scanning for Reactylon components. When a component is detected, it automatically imports the corresponding Babylon.js class and registers it with Reactylon, making it available in the rendering context. To remain consistent with Babylon.js' modular architecture, the plugin selects the *deepest available class* implementation by recursively scanning the directory tree. This approach ensures that the most specific and optimized module is used, preventing unwanted side effects that could compromise tree shaking.
100
+ The plugin analyzes your JSX code by scanning for Reactylon components. When a component is detected, it automatically imports the corresponding Babylon.js class and registers it with Reactylon, making it available in the rendering context. To remain consistent with Babylon.js modular architecture, the plugin selects the *deepest available class* implementation by recursively scanning the directory tree. This approach ensures that the most specific and optimized module is used, preventing unwanted side effects that could compromise tree shaking.
81
101
 
82
102
  ### Example
83
103
 
package/build/index.js CHANGED
@@ -99,7 +99,11 @@ export default declare((api) => {
99
99
  }
100
100
  }
101
101
  // Add implicit side effects (derived from static parse of JSX Reactylon code)
102
- const isPhysicsEngine = attributes.some(attr => t.isJSXAttribute(attr) && attr.name.name === "physicsOptions");
102
+ const isMultipleCanvas = type === 'Engine' && attributes.some(attr => t.isJSXAttribute(attr) && attr.name.name === "isMultipleCanvas");
103
+ if (isMultipleCanvas) {
104
+ sideEffects.push(t.importDeclaration([], t.stringLiteral('@babylonjs/core/Engines/AbstractEngine/abstractEngine.views')));
105
+ }
106
+ const isPhysicsEngine = type === 'Scene' && attributes.some(attr => t.isJSXAttribute(attr) && attr.name.name === "physicsOptions");
103
107
  if (isPhysicsEngine) {
104
108
  sideEffects.push(t.importDeclaration([], t.stringLiteral('@babylonjs/core/Physics/physicsEngineComponent.js')));
105
109
  }
@@ -141,7 +145,7 @@ export default declare((api) => {
141
145
  })),
142
146
  ]));
143
147
  const babylonImportDeclarations = babylonImports.map(([, importDeclaration]) => importDeclaration);
144
- // Add implicit prototype-level side effects (derived from static parse of JavaScript Babylon.js code)
148
+ // Add implicit prototype-level side effects (derived from static parse of JavaScript code, e.g. scene.createDefaultCameraOrLight)
145
149
  path.traverse({
146
150
  CallExpression(callPath) {
147
151
  const callee = callPath.node.callee;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-reactylon",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Babel plugin to enable tree-shaking of Babylon.js classes within a Reactylon application.",
5
5
  "main": "build/index.js",
6
6
  "type": "module",