Skip to content

feat: add tinyEngineBaseConfig as base viteconfig#583

Merged
hexqi merged 3 commits intoopentiny:refactor/developfrom
chilingling:feat/tinyEngineConfigPreset
Jun 29, 2024
Merged

feat: add tinyEngineBaseConfig as base viteconfig#583
hexqi merged 3 commits intoopentiny:refactor/developfrom
chilingling:feat/tinyEngineConfigPreset

Conversation

@chilingling
Copy link
Member

@chilingling chilingling commented Jun 15, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced htmlUpgradeHttpsPlugin to enhance security by upgrading HTTP requests to HTTPS.
    • Added devAliasPlugin to simplify module referencing during development.
  • Refactors

    • Updated Vite configuration setup to use useTinyEngineBaseConfig, streamlining configuration and improving maintainability.
    • Reorganized configuration logic across multiple files for better code structure.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 15, 2024

Walkthrough

The recent changes encapsulate a comprehensive refactor, consolidating shared Vite configuration logic into reusable functions and restructuring alias resolutions and environment handling. The refactor enhances modularity, clarity, and maintainability across various configuration files used in the Vite setup both in the core and template projects for TinyEngine.

Changes

File Path Change Summary
designer-demo/vite.config.js Refactored configuration, removed alias resolution, renamed parameters, and streamlined logic.
packages/build/vite-config/README.md Added documentation for tiny-engine-vite-config, detailing useTinyEngineBaseConfig function.
packages/build/vite-config/index.js Changed exports from getDefaultConfig to useTinyEngineBaseConfig.
packages/build/vite-config/src/default-config.js Moved config construction into getDefaultConfig, added new functions and plugins.
packages/build/vite-config/src/vite-plugins/devAliasPlugin.js Introduced devAliasPlugin for setting up development aliases.
packages/build/vite-config/src/vite-plugins/upgradeHttpsPlugin.js Introduced htmlUpgradeHttpsPlugin to add meta tags for upgrading HTTP to HTTPS.
packages/engine-cli/template/designer/vite.config.js Updated to use useTinyEngineBaseConfig and modified environment variable handling.

Poem

In Vite's embrace, the configs refined,

With aliases gone, and logic re-aligned.

TinyEngine's path clearer, more neat,

Modules together, configurations complete.

Hopkins' joy in this rabbit's rhyme,

Code's harmony, forever sublime. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (1)
packages/build/vite-config/src/default-config.js (1)

141-254: The overall structure of the configuration setup is complex and could benefit from further modularization to enhance clarity and ease of maintenance.

Consider further breaking down the configuration into separate modules or files, each handling a specific aspect of the Vite configuration. This would not only improve readability but also make the configuration more manageable and testable.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d5eaa6d and 5ecf296.

Files selected for processing (5)
  • designer-demo/vite.config.js (1 hunks)
  • packages/build/vite-config/index.js (1 hunks)
  • packages/build/vite-config/src/default-config.js (4 hunks)
  • packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (1 hunks)
  • packages/build/vite-config/src/vite-plugins/upgradeHttpsPlugin.js (1 hunks)
Additional comments not posted (7)
packages/build/vite-config/index.js (1)

1-1: Export of tinyEnginePreset looks good. Verify its usage across the project to ensure compatibility.

Verification successful

The tinyEnginePreset function is correctly imported and used in designer-demo/vite.config.js. Additionally, it is properly exported in packages/build/vite-config/index.js and defined in packages/build/vite-config/src/default-config.js. This confirms that the new export is in use and correctly integrated.

  • designer-demo/vite.config.js
  • packages/build/vite-config/index.js
  • packages/build/vite-config/src/default-config.js
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `tinyEnginePreset` across the project.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type javascript $'tinyEnginePreset'

Length of output: 74



Script:

#!/bin/bash
# Description: Verify the usage of `tinyEnginePreset` across the project.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type js 'tinyEnginePreset'

Length of output: 401

designer-demo/vite.config.js (2)

2-2: Import of tinyEnginePreset is correct.


4-18: Configuration using tinyEnginePreset looks comprehensive. Verify the paths and server settings to ensure they are appropriate for the environment.

Verification successful

Configuration using tinyEnginePreset looks comprehensive. Verify the paths and server settings to ensure they are appropriate for the environment.

#!/bin/bash
# Description: Verify the configuration settings in `designer-demo/vite.config.js`.

# Test: Check the paths and server settings.
cat designer-demo/vite.config.js | grep -E 'path.resolve|port'

Script:

#!/bin/bash
# Description: Verify the configuration settings in `designer-demo/vite.config.js`.

# Test: Check the paths and server settings.
cat designer-demo/vite.config.js | grep -E 'path.resolve|port'

Output:

+ cat designer-demo/vite.config.js
+ grep -E 'path.resolve|port'
import path from 'node:path'
import { tinyEnginePreset } from '@opentiny/tiny-engine-vite-config'
export default tinyEnginePreset({
  iconDirs: [path.resolve(__dirname, './node_modules/@opentiny/tiny-engine/assets/')],
  const envDir = path.resolve(process.cwd(), 'env')
    publicDir: path.resolve(__dirname, './public'),
      port: 8090

---

[observations] The script output confirms the presence of `path.resolve` and `port` within the configuration. The paths and server settings are defined as expected.
[analysis] The configuration appears to be correctly set up with appropriate paths and server settings.
[actions] Confirm the review comment as verified and provide the final response.
-->

Paths and server settings in `designer-demo/vite.config.js` are correctly configured.

- `iconDirs` path: `path.resolve(__dirname, './node_modules/@opentiny/tiny-engine/assets/')`
- `envDir` path: `path.resolve(process.cwd(), 'env')`
- `publicDir` path: `path.resolve(__dirname, './public')`
- Server port: `8090`



</details>


<details>
<summary>Scripts executed</summary>

The following scripts were executed for the analysis:



---

Script:
```shell
#!/bin/bash
# Description: Verify the configuration settings in `designer-demo/vite.config.js`.

# Test: Check the paths and server settings.
cat designer-demo/vite.config.js | grep -E 'path.resolve|port'

Length of output: 404

packages/build/vite-config/src/vite-plugins/upgradeHttpsPlugin.js (1)

3-30: Logic to include meta tags based on the mode in htmlUpgradeHttpsPlugin is sound. Verify its functionality in different environments.

Verification successful

Let's correct the script to use js as the file type and search for the htmlUpgradeHttpsPlugin function definition and its usage across the codebase.


Let's further investigate how htmlUpgradeHttpsPlugin is used in default-config.js to ensure it is correctly applied in 'alpha' and 'prod' environments.


The htmlUpgradeHttpsPlugin is correctly imported and used in packages/build/vite-config/src/default-config.js with the mode parameter. This ensures that the plugin's functionality to include meta tags based on the mode ('alpha' or 'prod') is applied correctly.

  • packages/build/vite-config/src/default-config.js:
    • Line: import { htmlUpgradeHttpsPlugin } from './vite-plugins/upgradeHttpsPlugin.js'
    • Line: htmlUpgradeHttpsPlugin(mode),
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the functionality of `htmlUpgradeHttpsPlugin` in different environments.

# Test: Check the plugin's behavior in 'alpha' and 'prod' modes.
rg --type javascript $'htmlUpgradeHttpsPlugin'

Length of output: 80



Script:

#!/bin/bash
# Description: Verify the functionality of `htmlUpgradeHttpsPlugin` in different environments.

# Test: Check the plugin's behavior in 'alpha' and 'prod' modes.
rg --type js 'htmlUpgradeHttpsPlugin'

Length of output: 365



Script:

#!/bin/bash
# Description: Verify the environments in which `htmlUpgradeHttpsPlugin` is used.

# Search for the usage of `htmlUpgradeHttpsPlugin` in `default-config.js`.
rg 'htmlUpgradeHttpsPlugin' packages/build/vite-config/src/default-config.js -A 5 -B 5

Length of output: 1126

packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (2)

3-62: Alias configurations in devAliasPlugin are extensive and well-defined. Ensure they are kept up-to-date with any package changes.


71-104: Conditional logic in devAliasPlugin to apply aliases based on the command is appropriate. Verify its effectiveness in differentiating development from production environments.

packages/build/vite-config/src/default-config.js (1)

Line range hint 1-17: Ensure all necessary imports are used and check for any potential unused imports.

@chilingling chilingling changed the title feat: add tinyEnginePreset as hoc viteconfig tool feat: add tinyEngineBaseConfig as base viteconfig Jun 19, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ecf296 and f4dd897.

Files selected for processing (4)
  • designer-demo/vite.config.js (1 hunks)
  • packages/build/vite-config/README.md (1 hunks)
  • packages/build/vite-config/index.js (1 hunks)
  • packages/build/vite-config/src/default-config.js (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/build/vite-config/index.js
  • packages/build/vite-config/src/default-config.js
Additional context used
Markdownlint
packages/build/vite-config/README.md

5-5: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

Additional comments not posted (2)
designer-demo/vite.config.js (2)

1-3: The import statements are correctly structured and relevant to the configuration setup.


5-23: The configuration setup using useTinyEngineBaseConfig and the merging with customConfig are implemented correctly.

@chilingling chilingling force-pushed the feat/tinyEngineConfigPreset branch from f4dd897 to 2c9bf49 Compare June 27, 2024 12:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
packages/build/vite-config/src/default-config.js (1)

Line range hint 140-245: Review useTinyEngineBaseConfig function for best practices and security.

The function effectively merges base and engine-specific configurations. However, ensure that the handling of CDN URLs (line 148) and the conditional logic for plugins based on environment variables (lines 205-229) are secure and performant. Consider using environment variable validation libraries to enhance security.

+ import validateEnv from 'env-validate';
+ validateEnv(env);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f4dd897 and 2c9bf49.

Files selected for processing (6)
  • designer-demo/vite.config.js (1 hunks)
  • packages/build/vite-config/README.md (1 hunks)
  • packages/build/vite-config/index.js (1 hunks)
  • packages/build/vite-config/src/default-config.js (5 hunks)
  • packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (1 hunks)
  • packages/build/vite-config/src/vite-plugins/upgradeHttpsPlugin.js (1 hunks)
Additional context used
Markdownlint
packages/build/vite-config/README.md

5-5: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

Additional comments not posted (7)
packages/build/vite-config/index.js (1)

1-1: Reminder: Integrate and document metaCommentsPlugin.

The past review highlighted the need for better integration and documentation of the metaCommentsPlugin. This is still relevant.

packages/build/vite-config/README.md (2)

1-28: Documentation for useTinyEngineBaseConfig looks comprehensive.

The documentation covers usage and configuration options well, providing clear guidance on how to use the new setup.

Tools
Markdownlint

5-5: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


5-5: Reduce multiple consecutive blank lines to a single blank line.

-
Tools
Markdownlint

5-5: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

designer-demo/vite.config.js (1)

5-23: Configuration using useTinyEngineBaseConfig is correctly implemented.

The use of mergeConfig to combine base and custom configurations is a good practice and is implemented correctly here.

packages/build/vite-config/src/vite-plugins/upgradeHttpsPlugin.js (1)

3-30: New htmlUpgradeHttpsPlugin is well implemented.

The conditional application of meta tags based on the environment (alpha or prod) is a good security practice. The implementation is clean and follows best practices for Vite plugins.

packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (1)

71-104: New devAliasPlugin effectively manages environment-specific aliases.

The implementation uses conditional logic based on the command to differentiate between serve and build modes, which is a best practice for Vite configurations.

packages/build/vite-config/src/default-config.js (1)

Line range hint 1-16: Review import statements and initial setup.

All imported modules and plugins appear to be correctly utilized in the configuration. Ensure that all dependencies are up-to-date and secure, especially plugins like monacoEditorPluginCjs and nodeModulesPolyfillPluginCjs.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2c9bf49 and e1ababf.

Files selected for processing (2)
  • packages/build/vite-config/README.md (1 hunks)
  • packages/engine-cli/template/designer/vite.config.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/build/vite-config/README.md
Additional comments not posted (3)
packages/engine-cli/template/designer/vite.config.js (3)

2-3: Review of import statements:

The import statements correctly load the necessary modules and functions for the Vite configuration. The import of useTinyEngineBaseConfig aligns with the PR's objective to refactor the configuration setup.


14-14: Review of local configuration setup:

The local configuration includes settings for envDir, publicDir, and the server's port. These are standard configurations that should work well with the base configuration. The use of mergeConfig to combine baseConfig and config is appropriate and should ensure that settings are correctly merged.

Also applies to: 21-21


21-21: Ensure proper configuration merging:

Using mergeConfig to combine configurations is a robust approach. However, ensure that there are no unintended overrides, especially in complex configurations.

@hexqi hexqi merged commit 570ccb8 into opentiny:refactor/develop Jun 29, 2024
yy-wow pushed a commit to yy-wow/tiny-engine that referenced this pull request Oct 10, 2024
* feat: add tinyEnginePreset as hoc viteconfig tool

* fix: change preset to base config function

* fix: sync change to template
@coderabbitai coderabbitai bot mentioned this pull request Apr 15, 2025
14 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jun 27, 2025
14 tasks
This was referenced Jul 24, 2025
@chilingling chilingling deleted the feat/tinyEngineConfigPreset branch February 27, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants