In-Browser Bundler for User Code Extension
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing techniques for compiling user code in custom digital twin web applications face issues such as compatibility with complex inputs, excessive compile time, and the burden of application configuration, particularly in browser environments, leading to failed compilations and user discouragement.
Innovation Solution
Compiling user code as an extension of a host application, where host packages are pre-compiled and exposed for in-browser use, eliminating the need for users to provide application configuration and reducing reliance on remote backends, utilizing a bundler and plugins like external globals, file resolver, code compiler, and styles plugins to transform and bundle code efficiently.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If user code is compiled in-browser using lightweight compilation, then compilation can be performed locally without remote backend, but compilation fails for complex inputs such as all Typescript inputs
Solution Approach 1:
The host application is pre-compiled before being loaded into the browser. This preliminary compilation action ensures that all host packages are ready in a compiled state, allowing user code to extend them without encountering compilation failures during browser-based compilation. The pre-compilation of host packages resolves the contradiction by ensuring reliability for complex inputs while maintaining in-browser operation.
2Ease of operation
If all remote packages are downloaded and compiled in-browser, then compilation can be performed locally, but compilation time becomes excessive
Solution Approach 1:
Remote packages are pre-compiled and cached before being needed by user code. This preliminary action eliminates the need to re-compile large remote packages during each user code compilation, dramatically reducing compilation time while maintaining local compilation capability.
Solution Approach 2:
Compiled versions of remote packages are cached and reused during user code compilation. Instead of re-compiling everything from source, the system uses pre-compiled copies of remote packages, significantly reducing the time required for in-browser compilation.
3Adaptability or versatility
If users provide application configuration information manually, then configuration can be customized, but the process is time consuming and discourages new users
Solution Approach 1:
The host application automatically provides its own configuration information to user code extensions. Instead of requiring users to manually configure everything, the system enables self-service where the host application's configuration is automatically inherited and made available to user code, eliminating configuration time while maintaining customization capability.
Solution Approach 2:
The host application serves multiple functions: it provides both the base application functionality and the configuration information that extensions need. This multi-functionality eliminates the need for separate configuration provision, reducing setup time while maintaining adaptability for different use cases.
4Ease of manufacture
If user code is compiled as a separate new application, then compilation can be performed independently, but additional remote requests are needed and compilation is less efficient
Solution Approach 1:
User code compilation is merged with the host application's compiled state. Instead of compiling user code as a completely separate new application, the system combines user code with the pre-compiled host application packages, creating an extended application. This merging approach maintains independent compilation capability while significantly improving efficiency by reusing pre-compiled host packages.
Data Source
AI summary
In an example embodiment, a technique is provided for compiling user code. A browser, executing on a local computing device, receives a request to compile the user code. A bundler, executing in the browser, retrieves contents of the user code and dependencies of the user code on one or more host packages of a host application. The bundler transforms, compiles and bundles the user code to produce a compiled bundle. The transforming imports each host package as a property of a global window object of the browser, wherein the property has a name that includes the host package name appended with a predetermined string, and a value that indicates an entry point into the host package. The compiles the user code as an extension of the host application in order to utilize the host packages in an already compiled form. The compiled bundle is then provided as an output.


