feat: add tinyEngineBaseConfig as base viteconfig#583
feat: add tinyEngineBaseConfig as base viteconfig#583hexqi merged 3 commits intoopentiny:refactor/developfrom
Conversation
WalkthroughThe 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
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
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
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 oftinyEnginePresetlooks good. Verify its usage across the project to ensure compatibility.Verification successful
The
tinyEnginePresetfunction is correctly imported and used indesigner-demo/vite.config.js. Additionally, it is properly exported inpackages/build/vite-config/index.jsand defined inpackages/build/vite-config/src/default-config.js. This confirms that the new export is in use and correctly integrated.
designer-demo/vite.config.jspackages/build/vite-config/index.jspackages/build/vite-config/src/default-config.jsScripts 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 oftinyEnginePresetis correct.
4-18: Configuration usingtinyEnginePresetlooks comprehensive. Verify the paths and server settings to ensure they are appropriate for the environment.Verification successful
Configuration using
tinyEnginePresetlooks 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 inhtmlUpgradeHttpsPluginis sound. Verify its functionality in different environments.Verification successful
Let's correct the script to use
jsas the file type and search for thehtmlUpgradeHttpsPluginfunction definition and its usage across the codebase.
Let's further investigate how
htmlUpgradeHttpsPluginis used indefault-config.jsto ensure it is correctly applied in 'alpha' and 'prod' environments.
The
htmlUpgradeHttpsPluginis correctly imported and used inpackages/build/vite-config/src/default-config.jswith themodeparameter. 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 5Length of output: 1126
packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (2)
3-62: Alias configurations indevAliasPluginare extensive and well-defined. Ensure they are kept up-to-date with any package changes.
71-104: Conditional logic indevAliasPluginto 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.
There was a problem hiding this comment.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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 usinguseTinyEngineBaseConfigand the merging withcustomConfigare implemented correctly.
f4dd897 to
2c9bf49
Compare
There was a problem hiding this comment.
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: ReviewuseTinyEngineBaseConfigfunction 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
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 documentmetaCommentsPlugin.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 foruseTinyEngineBaseConfiglooks 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 usinguseTinyEngineBaseConfigis correctly implemented.The use of
mergeConfigto 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: NewhtmlUpgradeHttpsPluginis well implemented.The conditional application of meta tags based on the environment (
alphaorprod) 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: NewdevAliasPlugineffectively manages environment-specific aliases.The implementation uses conditional logic based on the
commandto differentiate betweenserveandbuildmodes, 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
monacoEditorPluginCjsandnodeModulesPolyfillPluginCjs.
There was a problem hiding this comment.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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
useTinyEngineBaseConfigaligns 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'sport. These are standard configurations that should work well with the base configuration. The use ofmergeConfigto combinebaseConfigandconfigis appropriate and should ensure that settings are correctly merged.Also applies to: 21-21
21-21: Ensure proper configuration merging:Using
mergeConfigto combine configurations is a robust approach. However, ensure that there are no unintended overrides, especially in complex configurations.
* feat: add tinyEnginePreset as hoc viteconfig tool * fix: change preset to base config function * fix: sync change to template
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
htmlUpgradeHttpsPluginto enhance security by upgrading HTTP requests to HTTPS.devAliasPluginto simplify module referencing during development.Refactors
useTinyEngineBaseConfig, streamlining configuration and improving maintainability.