Skip to content

Clarify and Fix Plugin CSS Bundling #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 23, 2025
Merged

Conversation

coldenate
Copy link
Contributor

@coldenate coldenate commented Jul 23, 2025

Problem

I found there was confusion with new plugin developers trying to use CSS styles in their Plugins. They would use App.css, yet App.css would not ever be bundled properly. This led to situations where plugin-specific styles were not included in the final build, or all styles were merged into a single CSS file, making it unclear how to scope or reference styles per plugin.

Solution

  • Updated the webpack entry glob to use the canonical pattern ./src/widgets/**/*.tsx for robust, recursive matching of plugin entry points.
  • Removed the copying of README.md into the build output, as it is not needed for end-users.
  • These changes are what actually "did the fixing":
    • Ensured that each .tsx file (plugin entry) is allowed one corresponding .css file, as per the webpack.config.js setup.
    • Renamed the starter CSS files to make it clear that each plugin should have its own CSS file (e.g., index.css instead of App.css), and updated imports accordingly.
    • Updated the main plugin entry (index.tsx) to import ../index.css instead of ../App.css, aligning with the new convention and ensuring the correct CSS is bundled.
  • Cleaned up and clarified the webpack config for better maintainability and developer experience.

Summary by CodeRabbit

  • Chores
    • Updated import styles and file references for consistency.
    • Improved configuration patterns for better maintainability.
    • Standardized code formatting and simplified plugin settings.
    • Streamlined build process by removing redundant file copying steps.

@coldenate coldenate self-assigned this Jul 23, 2025
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

The changes modify import syntax and CSS file reference in a TypeScript widget index file, broaden the webpack entry glob pattern to include nested subdirectories, refactor entry object construction and formatting in the webpack config, and remove the README copy step from the build script in package.json. No functional logic or exported interfaces were altered.

Changes

File(s) Change Summary
src/widgets/index.tsx Changed ReactRNPlugin import to type-only; updated CSS import from ../App.css to ../index.css.
webpack.config.js Expanded entry glob to include nested .tsx files; refactored entry object creation to use arrow function with normalized paths; standardized string quotes; reformatted plugin config and dev server headers for consistency.
package.json Removed copying README.md to dist in build script; updated build command to skip README copy step.

Estimated code review effort

1 (~5 minutes)

Poem

In the meadow of code, a bunny hops by,
Tweaking imports and patterns with a keen, watchful eye.
CSS paths now tidy, configs neat as a pin,
With webpack and widgets, let the builds begin!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b546c0 and cff4c63.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • webpack.config.js (4 hunks)
✅ Files skipped from review due to trivial changes (2)
  • package.json
  • webpack.config.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

@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: 0

🔭 Outside diff range comments (1)
webpack.config.js (1)

22-26: Potential key-collision in the dynamic entry map

path.parse(el).name extracts only the basename of every matched file.
With the new recursive glob (./src/widgets/**/*.tsx) two widgets in different sub-folders that share the same filename (e.g. index.tsx) will overwrite each other in the obj literal, silently dropping one bundle.

Consider deriving the key from the relative path to guarantee uniqueness:

-entry: glob.sync('./src/widgets/**/*.tsx').reduce((obj, el) => {
-  obj[path.parse(el).name] = el;
-  obj[path.parse(el).name + SANDBOX_SUFFIX] = el;
+entry: glob.sync('./src/widgets/**/*.tsx').reduce((obj, el) => {
+  const rel = path
+    .relative('src/widgets', el)            // e.g.  foo/bar/index.tsx
+    .replace(/\.[tj]sx?$/, '')              // strip extension
+    .replace(/\\/g, '/');                   // Windows → POSIX
+
+  obj[rel] = el;
+  obj[`${rel}${SANDBOX_SUFFIX}`] = el;
   return obj;
 }, {}),
🧹 Nitpick comments (2)
webpack.config.js (1)

50-54: Minor: avoid pushing undefined into the use array

When isDevelopment is false the current ternary yields the loader instance; when true the expression yields 'style-loader', so both paths are OK.
However, an earlier pattern (isDevelopment ? undefined : …) added undefined into plugins and was later filtered via .filter(Boolean).
For consistency you could follow the same pattern here or vice-versa.
No functional impact, purely cosmetic.

src/widgets/index.tsx (1)

2-4: Duplicate / unclear CSS imports

Both ../style.css and ../index.css are imported.
Given the PR’s intent to standardise on index.css, confirm that style.css is still required; otherwise drop it to avoid duplicate rules and larger bundles.

-import '../style.css';
-import '../index.css';
+import '../index.css';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9c1590 and df0403d.

📒 Files selected for processing (2)
  • src/widgets/index.tsx (1 hunks)
  • webpack.config.js (4 hunks)
🔇 Additional comments (2)
webpack.config.js (1)

91-93: 👍 Copy-plugin simplification looks good

Removing the redundant README.md copy makes the bundle leaner and avoids leaking repo docs into user downloads.

src/widgets/index.tsx (1)

1-1: Good use of type-only import

Switching to type ReactRNPlugin prevents tree-shaking from pulling runtime code into the bundle.
Nice touch.

@coldenate
Copy link
Contributor Author

Walkthrough

The changes modify import syntax and CSS file reference in a TypeScript widget index file, broaden the webpack entry glob pattern to include nested subdirectories, refactor entry object construction and formatting in the webpack config, and remove the README copy step from the build script in package.json. No functional logic or exported interfaces were altered.

Changes

File(s) Change Summary
src/widgets/index.tsx Changed ReactRNPlugin import to type-only; updated CSS import from ../App.css to ../index.css.
webpack.config.js Expanded entry glob to include nested .tsx files; refactored entry object creation to use arrow function with normalized paths; standardized string quotes; reformatted plugin config and dev server headers for consistency.
package.json Removed copying README.md to dist in build script; updated build command to skip README copy step.

Estimated code review effort

1 (~5 minutes)

Poem

In the meadow of code, a bunny hops by,
Tweaking imports and patterns with a keen, watchful eye.
CSS paths now tidy, configs neat as a pin,
With webpack and widgets, let the builds begin!
🐇✨

📜 Recent review details
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

I pushed some fixes, please review them.

Copy link

coderabbitai bot commented Jul 23, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll review the recent changes you've pushed. Let me examine the latest commits and file changes.


🏁 Script executed:

#!/bin/bash
# Check recent commits to see what fixes were pushed
git log --oneline -10

# Check the current state of the main files mentioned in the PR
echo "=== Current src/widgets/index.tsx ==="
cat src/widgets/index.tsx

echo -e "\n=== Current webpack.config.js ==="
cat webpack.config.js

echo -e "\n=== Current package.json ==="
cat package.json

# Check if there's an index.css file that replaced App.css
echo -e "\n=== Checking for CSS files ==="
find . -name "*.css" -type f | head -10

Length of output: 6349


@coldenate, I've reviewed the current state of your files, and I notice some discrepancies between the intended changes described in the PR and the actual current state of the code. Here are the issues I found:

Issues Found:

1. Webpack Entry Pattern Not Updated

The webpack.config.js still uses the old glob pattern:

entry: glob.sync('./src/widgets/**.tsx').reduce((obj, el) => {

It should be updated to:

entry: glob.sync('./src/widgets/**/*.tsx').reduce((obj, el) => {

2. README.md Still Being Copied

The CopyPlugin in webpack.config.js still includes copying the README:

new CopyPlugin({
  patterns: [
    { from: 'public', to: '' },
    { from: 'README.md', to: '' }, // This should be removed
  ],
}),

3. Duplicate CSS Imports

The src/widgets/index.tsx file currently imports both CSS files:

import '../style.css';
import '../index.css';

Based on the PR objectives, it should only import ../index.css.

4. Missing Build Script Update

The package.json build script appears correct (no README copy), but the webpack config contradicts this.

Recommendations:

  1. Fix the webpack glob pattern to properly match nested .tsx files
  2. Remove the README.md copy from the CopyPlugin patterns
  3. Remove the duplicate CSS import - keep only ../index.css
  4. Ensure consistency between the build script and webpack configuration

These fixes will align your code with the PR objectives of clarifying CSS bundling and removing unnecessary README copying.

@coldenate coldenate merged commit 7f4ec1b into main Jul 23, 2025
1 check passed
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.

1 participant