How kaminaly/react-pug-react-scripts works
Main Components
• CLI/Entry Point: Show the “bin” folder (especially the react-scripts.js file) that serves as the main executable for developers. It kick-starts the application lifecycle.
• Configuration: Include a “config” component that bundles environment settings, webpack configurations (webpack.config.js and webpackDevServer.config.js), Jest configurations (and its subfiles like babelTransform.js, cssTransform.js, fileTransform.js), and other module/path settings. This represents the customization layer that integrates react-pug.
• Scripts: Represent the “scripts” directory which contains build.js, start.js, test.js, eject.js, and supporting utility modules. These scripts control building, development, testing, and eject operations.
• Test Fixtures: Add a component for “fixtures” (specifically the kitchensink example) that includes test projects complete with environment files, integration tests, source files (React components, features for syntax support, webpack asset tests) to ensure the customization works as expected.
• Templates: Show both “template” and “template-typescript” directories. These provide starter projects that users will get when they create a new app using this custom react-scripts.
• Library/Type Definitions: A component for the “lib” directory, which houses type definitions such as react-app.d.ts, helps clarify any TypeScript-specific extensions or interfaces.
Relationships and Data Flow
• A user (developer) uses the CLI tool (via npx create-react-app with the special scripts version) to bootstrap a project.
• This command triggers the “bin/react-scripts.js” which, using the configurations from the “config” directory, sets up the environment.
• Depending on the developer’s actions (starting, testing, building, ejecting), corresponding scripts (inside the “scripts” folder) are called.
• During the build and runtime process, webpack and Babel configurations (from “config/webpack.config.js” and Babel transforms) apply transformations such as converting Pug templates through babel-plugin-transform-react-pug.
• Test and integration files (in “fixtures”) ensure these processes work as intended, while the “template” directories provide the initial structure for projects created with this tool.
Architectural Patterns and Key Technologies
• The separation of configuration, scripts, templates, and test fixtures demonstrates modular architecture. This division mirrors the design in the original create-react-app while adding a new transformation layer.
• That the customization revolves around integrating a Babel plugin (babel-plugin-transform-react-pug) to support Pug in React alongside typical React app building.
• How environment variables (using various .env files in fixtures) and testing setups (Jest in “config/jest” and integration tests) are organized.
• Mention that there is special handling for TypeScript projects with dedicated templates (template-typescript) and type definitions (in “lib”).