Pedal-Intelligence / saypi-userscript

An independent voice interface for Inflection AI's conversational assistant, Pi
https://www.saypi.ai/
Other
15 stars 3 forks source link

Say, Pi v1.4.6 - Bundle Optimisation #41

Closed rosscado closed 8 months ago

rosscado commented 8 months ago

This update is primarily focused on optimising the bundle size by modifying the loading mechanism for the audio module. By refactoring the webpack configuration and employing a remote fetching strategy for the audio module, we've significantly reduced the user script size, ensuring it stays below the 2MB limit imposed by the hosting platform, while maintaining the functionality and performance.

Changes:

  1. ES6 Modules

    • Converted all dependencies (internal and external) from CommonJS requires syntax to ES6 import/export syntax
    • Allows for tree shaking and static dependency analysis
  2. Webpack Configuration:

    • Introduced a production build mode to the webpack configuration to ensure better optimisation during the build process.
    • Adjusted the output file naming and path resolution to properly handle the main script and the audio module.
    • Configured the webpack to avoid minification in production mode as per the guidelines of the hosting platform.
  3. Audio Module Loading:

    • Implemented a remote fetching mechanism for loading the audio module to reduce the bundle size.
    • Ensured the fetch request adheres to CORS and SSL configurations for both development and production environments.
  4. Server Configuration:

    • Updated the server launch condition to properly identify the script execution context.
  5. Environment Variables:

    • Ensured that the production build uses the .env.production file for loading environment variables.

Benefits:

Testing:

Deployment:

Future Work: