├── .changeset ├── README.md └── config.json ├── .github └── workflows │ ├── node.js.yml │ └── release.yml ├── .gitignore ├── .husky └── pre-commit ├── .prettierignore ├── .yarn └── releases │ └── yarn-3.1.1.cjs ├── LICENSE ├── README.md ├── config └── craco.config.js ├── examples ├── with-javascript │ ├── .gitignore │ ├── .swcrc │ ├── README.md │ ├── craco.config.js │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ └── setupTests.js ├── with-svgr │ ├── .gitignore │ ├── README.md │ ├── craco.config.js │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ └── setupTests.js └── with-typescript │ ├── .gitignore │ ├── README.md │ ├── craco.config.js │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt │ ├── src │ ├── App.css │ ├── App.test.tsx │ ├── App.tsx │ ├── index.css │ ├── index.tsx │ ├── logo.svg │ ├── react-app-env.d.ts │ └── setupTests.ts │ └── tsconfig.json ├── package.json ├── packages └── craco-swc │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ └── src │ └── index.js ├── pnpm-lock.yaml └── pnpm-workspace.yaml /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { "repo": "pradel/create-react-app-swc" } 6 | ], 7 | "commit": false, 8 | "linked": [], 9 | "access": "public", 10 | "baseBranch": "main", 11 | "updateInternalDependencies": "patch", 12 | "ignore": [] 13 | } 14 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | name: Node.js CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | # Test default react-scripts to compare time 11 | test-react-scripts: 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | node-version: [14.x, 16.x] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | 21 | - uses: pnpm/action-setup@v2.0.1 22 | with: 23 | version: 6.23.1 24 | 25 | - name: Use Node.js ${{ matrix.node-version }} 26 | uses: actions/setup-node@v2 27 | with: 28 | node-version: ${{ matrix.node-version }} 29 | cache: 'pnpm' 30 | 31 | - name: Install dependencies 32 | run: pnpm install 33 | 34 | - name: Compile create-react-app examples using react-scripts 35 | run: | 36 | pnpm run build-react-scripts --filter "with-*" 37 | 38 | - name: Test create-react-app examples using react-scripts 39 | run: | 40 | pnpm run test-react-scripts --filter "with-*" 41 | 42 | # Test craco without any config to compare time 43 | test-craco-empty: 44 | runs-on: ubuntu-latest 45 | 46 | strategy: 47 | matrix: 48 | node-version: [14.x, 16.x] 49 | 50 | steps: 51 | - uses: actions/checkout@v2 52 | 53 | - uses: pnpm/action-setup@v2.0.1 54 | with: 55 | version: 6.23.1 56 | 57 | - name: Use Node.js ${{ matrix.node-version }} 58 | uses: actions/setup-node@v2 59 | with: 60 | node-version: ${{ matrix.node-version }} 61 | cache: 'pnpm' 62 | 63 | - name: Install dependencies 64 | run: pnpm install 65 | 66 | - name: Compile create-react-app examples using craco 67 | run: | 68 | pnpm run build --filter "with-*" -- --config ../../config/craco.config.js 69 | 70 | - name: Test create-react-app examples using craco 71 | run: | 72 | pnpm run test --filter "with-*" -- --config ../../config/craco.config.js 73 | 74 | test: 75 | runs-on: ubuntu-latest 76 | 77 | strategy: 78 | matrix: 79 | node-version: [14.x, 16.x] 80 | 81 | steps: 82 | - uses: actions/checkout@v2 83 | 84 | - uses: pnpm/action-setup@v2.0.1 85 | with: 86 | version: 6.23.1 87 | 88 | - name: Use Node.js ${{ matrix.node-version }} 89 | uses: actions/setup-node@v2 90 | with: 91 | node-version: ${{ matrix.node-version }} 92 | cache: 'pnpm' 93 | 94 | - name: Install dependencies 95 | run: pnpm install 96 | 97 | - name: Compile create-react-app examples using craco 98 | run: | 99 | pnpm run build --filter "with-*" 100 | 101 | - name: Test create-react-app examples using craco 102 | run: | 103 | pnpm run test --filter "with-*" 104 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | 7 | jobs: 8 | release: 9 | name: Release 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout Repo 13 | uses: actions/checkout@v2 14 | with: 15 | # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits 16 | fetch-depth: 0 17 | 18 | - uses: pnpm/action-setup@v2.0.1 19 | with: 20 | version: 6.23.1 21 | 22 | - name: Use Node.js 16.x 23 | uses: actions/setup-node@v2 24 | with: 25 | node-version: 16.x 26 | cache: 'pnpm' 27 | 28 | - name: Install dependencies 29 | run: pnpm install 30 | 31 | - name: Create Release Pull Request or Publish to npm 32 | id: changesets 33 | uses: changesets/action@v1 34 | with: 35 | version: pnpm run version 36 | publish: pnpm run release 37 | commit: 'chore: update versions' 38 | title: 'chore: version packages' 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | pnpx lint-staged 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Léo Pradel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚀 create-react-app-swc 🚀 2 | 3 | Use [swc](https://swc.rs/) in your [create-react-app](https://create-react-app.dev/) for faster compilation, development and tests. 4 | 5 | ## Features 6 | 7 | - javascript / typescript support 8 | - Replace babel-loader with swc during development 9 | - Replace babel-loader with swc for faster build time 10 | - Replace babel with swc when running jest tests 11 | 12 | ## Getting started 13 | 14 | Follow the [guide](https://github.com/pradel/create-react-app-swc/blob/main/packages/craco-swc/README.md) to setup your project. 15 | 16 | ## FAQ 17 | 18 | ### Why is it faster? 19 | 20 | Internally create-react-app use babel to compile the javascript / typescript files of your application. By using craco-swc, you use the [swc](https://swc.rs/) compiler to compile your app instead of babel. swc is a super fast javascript / typescript compiler written in Rust. 21 | 22 | ### What is craco and why do I need it? 23 | 24 | [craco](https://github.com/gsoft-inc/craco) (**C**reate **R**eact **A**pp **C**onfiguration **O**verride) is an easy and comprehensible configuration layer for create-react-app. By using craco you can customise the create-react-app configuration without ejecting. 25 | 26 | ### What are the differences with create-react-app? 27 | 28 | - Since babel is not used, you won't be able to use the babel plugins (eg: `babel-plugin-macros`, `babel-plugin-transform-react-remove-prop-types`, ...). 29 | - No flow support 30 | 31 | ## License 32 | 33 | MIT © [Léo Pradel](https://www.leopradel.com/) 34 | -------------------------------------------------------------------------------- /config/craco.config.js: -------------------------------------------------------------------------------- 1 | // Empty craco config used by the examples 2 | module.exports = {}; 3 | -------------------------------------------------------------------------------- /examples/with-javascript/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /examples/with-javascript/.swcrc: -------------------------------------------------------------------------------- 1 | { 2 | "jsc": { 3 | "target": "es2015", 4 | "transform": { 5 | "react": { 6 | "runtime": "automatic" 7 | } 8 | }, 9 | "parser": { 10 | "syntax": "ecmascript", 11 | "jsx": true 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/with-javascript/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /examples/with-javascript/craco.config.js: -------------------------------------------------------------------------------- 1 | const cracoSwcPlugin = require('craco-swc'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | { 6 | plugin: cracoSwcPlugin, 7 | }, 8 | ], 9 | }; 10 | -------------------------------------------------------------------------------- /examples/with-javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-javascript", 3 | "version": "0.0.3", 4 | "private": true, 5 | "dependencies": { 6 | "@craco/craco": "6.4.3", 7 | "@testing-library/jest-dom": "^5.16.3", 8 | "@testing-library/react": "^12.1.4", 9 | "@testing-library/user-event": "^13.5.0", 10 | "craco-swc": "workspace:craco-swc", 11 | "react": "^17.0.2", 12 | "react-dom": "^17.0.2", 13 | "react-scripts": "5.0.0", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "craco start", 18 | "start-react-scripts": "react-scripts start", 19 | "build": "craco build", 20 | "build-react-scripts": "react-scripts build", 21 | "test": "craco test", 22 | "test-react-scripts": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/with-javascript/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-javascript/public/favicon.ico -------------------------------------------------------------------------------- /examples/with-javascript/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/with-javascript/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-javascript/public/logo192.png -------------------------------------------------------------------------------- /examples/with-javascript/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-javascript/public/logo512.png -------------------------------------------------------------------------------- /examples/with-javascript/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /examples/with-javascript/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /examples/with-javascript/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/with-javascript/src/App.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | 4 | function App() { 5 | return ( 6 |
7 |
8 | logo 9 |

10 | Edit src/App.js and save to reload. 11 |

12 | 18 | Learn React 19 | 20 |
21 |
22 | ); 23 | } 24 | 25 | export default App; 26 | -------------------------------------------------------------------------------- /examples/with-javascript/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/with-javascript/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-javascript/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /examples/with-javascript/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/with-javascript/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /examples/with-svgr/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /examples/with-svgr/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /examples/with-svgr/craco.config.js: -------------------------------------------------------------------------------- 1 | const cracoSwcPlugin = require('craco-swc'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | { 6 | plugin: cracoSwcPlugin, 7 | }, 8 | ], 9 | }; 10 | -------------------------------------------------------------------------------- /examples/with-svgr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-svgr", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@craco/craco": "6.4.3", 7 | "@testing-library/jest-dom": "^5.16.3", 8 | "@testing-library/react": "^12.1.4", 9 | "@testing-library/user-event": "^13.5.0", 10 | "craco-swc": "workspace:craco-swc", 11 | "react": "^17.0.2", 12 | "react-dom": "^17.0.2", 13 | "react-scripts": "5.0.0", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "craco start", 18 | "start-react-scripts": "react-scripts start", 19 | "build": "craco build", 20 | "build-react-scripts": "react-scripts build", 21 | "test": "craco test", 22 | "test-react-scripts": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/with-svgr/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-svgr/public/favicon.ico -------------------------------------------------------------------------------- /examples/with-svgr/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/with-svgr/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-svgr/public/logo192.png -------------------------------------------------------------------------------- /examples/with-svgr/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-svgr/public/logo512.png -------------------------------------------------------------------------------- /examples/with-svgr/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /examples/with-svgr/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /examples/with-svgr/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/with-svgr/src/App.js: -------------------------------------------------------------------------------- 1 | import { ReactComponent as Logo } from './logo.svg'; 2 | import './App.css'; 3 | 4 | function App() { 5 | return ( 6 |
7 |
8 | 9 |

10 | Edit src/App.js and save to reload. 11 |

12 | 18 | Learn React 19 | 20 |
21 |
22 | ); 23 | } 24 | 25 | export default App; 26 | -------------------------------------------------------------------------------- /examples/with-svgr/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/with-svgr/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-svgr/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /examples/with-svgr/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/with-svgr/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /examples/with-typescript/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /examples/with-typescript/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /examples/with-typescript/craco.config.js: -------------------------------------------------------------------------------- 1 | const cracoSwcPlugin = require('craco-swc'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | { 6 | plugin: cracoSwcPlugin, 7 | }, 8 | ], 9 | }; 10 | -------------------------------------------------------------------------------- /examples/with-typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-typescript", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@craco/craco": "6.4.3", 7 | "@testing-library/jest-dom": "^5.16.3", 8 | "@testing-library/react": "^12.1.4", 9 | "@testing-library/user-event": "^13.5.0", 10 | "@types/jest": "^27.4.1", 11 | "@types/node": "^16.11.26", 12 | "@types/react": "^17.0.43", 13 | "@types/react-dom": "^17.0.14", 14 | "craco-swc": "workspace:craco-swc", 15 | "react": "^17.0.2", 16 | "react-dom": "^17.0.2", 17 | "react-scripts": "5.0.0", 18 | "typescript": "^4.6.3", 19 | "web-vitals": "^2.1.4" 20 | }, 21 | "scripts": { 22 | "start": "craco start", 23 | "start-react-scripts": "react-scripts start", 24 | "build": "craco build", 25 | "build-react-scripts": "react-scripts build", 26 | "test": "craco test", 27 | "test-react-scripts": "react-scripts test", 28 | "eject": "react-scripts eject" 29 | }, 30 | "eslintConfig": { 31 | "extends": [ 32 | "react-app", 33 | "react-app/jest" 34 | ] 35 | }, 36 | "browserslist": { 37 | "production": [ 38 | ">0.2%", 39 | "not dead", 40 | "not op_mini all" 41 | ], 42 | "development": [ 43 | "last 1 chrome version", 44 | "last 1 firefox version", 45 | "last 1 safari version" 46 | ] 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/with-typescript/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-typescript/public/favicon.ico -------------------------------------------------------------------------------- /examples/with-typescript/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/with-typescript/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-typescript/public/logo192.png -------------------------------------------------------------------------------- /examples/with-typescript/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pradel/create-react-app-swc/d5d2c0e216a5080632868250abb8b97ad272dba5/examples/with-typescript/public/logo512.png -------------------------------------------------------------------------------- /examples/with-typescript/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /examples/with-typescript/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /examples/with-typescript/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/with-typescript/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/with-typescript/src/App.tsx: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | 4 | function App() { 5 | return ( 6 |
7 |
8 | logo 9 |

10 | Edit src/App.tsx and save to reload. 11 |

12 | 18 | Learn React 19 | 20 |
21 |
22 | ); 23 | } 24 | 25 | export default App; 26 | -------------------------------------------------------------------------------- /examples/with-typescript/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-typescript/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /examples/with-typescript/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/with-typescript/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /examples/with-typescript/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /examples/with-typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "noFallthroughCasesInSwitch": true, 12 | "module": "esnext", 13 | "moduleResolution": "node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"] 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "prettier": "prettier --write \"**/*.{js,ts,tsx,css,scss,json,md,mdx,yml}\"", 5 | "version": "pnpx changeset version && pnpm install --lockfile-only", 6 | "release": "pnpx changeset publish", 7 | "prepare": "husky install" 8 | }, 9 | "prettier": { 10 | "singleQuote": true 11 | }, 12 | "husky": { 13 | "hooks": { 14 | "pre-commit": "lint-staged" 15 | } 16 | }, 17 | "lint-staged": { 18 | "*.{js,ts,tsx,css,scss,json,md,mdx,yml}": [ 19 | "prettier --write", 20 | "git add" 21 | ] 22 | }, 23 | "devDependencies": { 24 | "@changesets/changelog-github": "0.4.4", 25 | "@changesets/cli": "2.22.0", 26 | "husky": "7.0.4", 27 | "lint-staged": "12.3.7", 28 | "prettier": "2.6.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/craco-swc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # craco-swc 2 | 3 | ## 0.5.1 4 | 5 | ### Patch Changes 6 | 7 | - [#22](https://github.com/pradel/create-react-app-swc/pull/22) [`312ba63`](https://github.com/pradel/create-react-app-swc/commit/312ba631a42071f9423c7aa049658480c422a3bc) Thanks [@pradel](https://github.com/pradel)! - Add @craco/craco 7 to peer dependencies. 8 | 9 | ## 0.5.0 10 | 11 | ### Minor Changes 12 | 13 | - [#19](https://github.com/pradel/create-react-app-swc/pull/19) [`db2a394`](https://github.com/pradel/create-react-app-swc/commit/db2a394199cbbcccc3defa3641d35f18743a3002) Thanks [@pradel](https://github.com/pradel)! - Add svgr support. 14 | 15 | ## 0.4.0 16 | 17 | ### Minor Changes 18 | 19 | - [#13](https://github.com/pradel/create-react-app-swc/pull/13) [`5559703`](https://github.com/pradel/create-react-app-swc/commit/555970354cf648a12d577a0c1c98b5661543a158) Thanks [@pradel](https://github.com/pradel)! - Enable react automatic runtime by default, you don't need to import React anymore! 20 | 21 | ## 0.3.0 22 | 23 | ### Minor Changes 24 | 25 | - [#16](https://github.com/pradel/create-react-app-swc/pull/16) [`d93de43`](https://github.com/pradel/create-react-app-swc/commit/d93de43bce06bc7e9c87c2b7d165f9922d82e622) Thanks [@pradel](https://github.com/pradel)! - 🚀 create-react-app 5 is now supported 🚀 26 | 27 | ## Breaking Changes 28 | 29 | - Drop support for CRA 3 and 4. As many underlying libraries have changed, CRA 4 and 3 are no longer supported. Check the [CRA changelog](https://github.com/facebook/create-react-app/releases/tag/v5.0.0) to see what changed. 30 | 31 | ## Migrating from 0.2.X to 0.3.X 32 | 33 | - You will first need to migrate your project to CRA 5. See the CRA [Migration guide](https://github.com/facebook/create-react-app/releases/tag/v5.0.0) for more information. 34 | - Upgrade `craco-swc` to version 0.3.0 or higher in your project. 35 | 36 | ## 0.2.0 37 | 38 | ### Minor Changes 39 | 40 | - [#10](https://github.com/pradel/create-react-app-swc/pull/10) [`172ec25`](https://github.com/pradel/create-react-app-swc/commit/172ec25a10f8eb2e42bde36e7f3e4d264e23aec4) Thanks [@pradel](https://github.com/pradel)! - Upgrade dependencies 41 | -------------------------------------------------------------------------------- /packages/craco-swc/README.md: -------------------------------------------------------------------------------- 1 | # 🚀 craco-swc 🚀 2 | 3 | Use [swc](https://swc.rs/) in your [create-react-app](https://create-react-app.dev/) with [craco](https://github.com/gsoft-inc/craco) for faster compilation, development and tests. 4 | 5 | ## Features 6 | 7 | - Replace babel-loader with swc during development 8 | - Replace babel-loader with swc for faster build time 9 | - Use swc when running jest 10 | 11 | ## Installation 12 | 13 | Run the following command to install `craco-swc` in your project: 14 | 15 | ```sh 16 | yarn add --dev craco-swc @craco/craco 17 | 18 | # OR 19 | 20 | npm install --save-dev craco-swc @craco/craco 21 | ``` 22 | 23 | ## Usage 24 | 25 | Add this configuration to your `craco.config.js` configuration file: 26 | 27 | ```js 28 | // craco.config.js 29 | const CracoSwcPlugin = require('craco-swc'); 30 | 31 | module.exports = { 32 | plugins: [{ plugin: CracoSwcPlugin }], 33 | }; 34 | ``` 35 | 36 | To use `craco` instead of `react-scripts` to manage our application, edit the `scripts` section of your `package.json`. 37 | 38 | ```diff 39 | /* package.json */ 40 | 41 | "scripts": { 42 | - "start": "react-scripts start", 43 | + "start": "craco start", 44 | - "build": "react-scripts build", 45 | + "build": "craco build" 46 | - "test": "react-scripts test", 47 | + "test": "craco test" 48 | } 49 | ``` 50 | 51 | ## Configuration 52 | 53 | If your project contains a `.swcrc` file, it will be used by the `swc` loader configuration. 54 | Take a look at https://swc.rs/docs/configuring-swc#jsc to see the list of available options. 55 | 56 | You can also configure the options of the plugin by passing an `options` object. 57 | 58 | - `swcLoaderOptions`: customise the options passed down to the `swc` loader. _Note: This will be used only by webpack_ 59 | 60 | For example add this configuration to your `craco.config.js` configuration file: 61 | 62 | ```js 63 | // craco.config.js 64 | const CracoSwcPlugin = require('craco-swc'); 65 | 66 | module.exports = { 67 | plugins: [ 68 | { 69 | plugin: CracoSwcPlugin, 70 | options: { 71 | swcLoaderOptions: { 72 | jsc: { 73 | externalHelpers: true, 74 | target: 'es2015', 75 | parser: { 76 | syntax: 'ecmascript', 77 | jsx: true, 78 | dynamicImport: true, 79 | exportDefaultFrom: true, 80 | }, 81 | }, 82 | }, 83 | }, 84 | }, 85 | ], 86 | }; 87 | ``` 88 | 89 | ## License 90 | 91 | MIT © [Léo Pradel](https://www.leopradel.com/) 92 | -------------------------------------------------------------------------------- /packages/craco-swc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "craco-swc", 3 | "version": "0.5.1", 4 | "main": "src/index.js", 5 | "repository": "https://github.com/pradel/create-react-app-swc.git", 6 | "author": "Leo Pradel ", 7 | "license": "MIT", 8 | "files": [ 9 | "src" 10 | ], 11 | "peerDependencies": { 12 | "@craco/craco": "^6 || ^7", 13 | "react-scripts": "^5" 14 | }, 15 | "dependencies": { 16 | "@swc/core": "^1.2.161", 17 | "@swc/helpers": "^0.3.8", 18 | "@swc/jest": "^0.2.20", 19 | "swc-loader": "^0.1.15" 20 | }, 21 | "devDependencies": { 22 | "@craco/craco": "6.4.3", 23 | "react-scripts": "5.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/craco-swc/src/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const { loaderByName, removeLoaders, addAfterLoader } = require('@craco/craco'); 4 | 5 | module.exports = { 6 | /** 7 | * To process the js/ts files we replace the babel-loader with the swc-loader 8 | */ 9 | overrideWebpackConfig: ({ 10 | webpackConfig, 11 | pluginOptions, 12 | context: { paths }, 13 | }) => { 14 | const useTypeScript = fs.existsSync(paths.appTsConfig); 15 | const appSwcConfig = path.resolve(paths.appPath, '.swcrc'); 16 | const useSwcConfig = fs.existsSync(appSwcConfig); 17 | 18 | // add swc-loader 19 | addAfterLoader(webpackConfig, loaderByName('babel-loader'), { 20 | test: /\.(js|mjs|jsx|ts|tsx)$/, 21 | include: paths.appSrc, 22 | loader: require.resolve('swc-loader'), 23 | options: 24 | pluginOptions && pluginOptions.swcLoaderOptions 25 | ? pluginOptions.swcLoaderOptions 26 | : useSwcConfig 27 | ? // If there is an .swcrc file at the root of the project we pass undefined 28 | // That way swc will use the .swcrc config 29 | undefined 30 | : { 31 | jsc: { 32 | target: 'es2015', 33 | externalHelpers: true, 34 | transform: { 35 | react: { 36 | runtime: 'automatic', 37 | }, 38 | }, 39 | parser: useTypeScript 40 | ? { 41 | syntax: 'typescript', 42 | tsx: true, 43 | dynamicImport: true, 44 | } 45 | : { 46 | syntax: 'ecmascript', 47 | jsx: true, 48 | dynamicImport: true, 49 | }, 50 | }, 51 | }, 52 | }); 53 | 54 | // remove the babel loaders 55 | removeLoaders(webpackConfig, loaderByName('babel-loader')); 56 | 57 | return webpackConfig; 58 | }, 59 | 60 | /** 61 | * To process the js/ts files we replace the babel-loader with the swc jest loader 62 | */ 63 | overrideJestConfig: ({ jestConfig, pluginOptions, context: { paths } }) => { 64 | const useTypeScript = fs.existsSync(paths.appTsConfig); 65 | const appSwcConfig = path.resolve(paths.appPath, '.swcrc'); 66 | const useSwcConfig = fs.existsSync(appSwcConfig); 67 | const swcConfig = useSwcConfig 68 | ? JSON.parse(fs.readFileSync(appSwcConfig, 'utf-8')) 69 | : null; 70 | 71 | // Replace babel transform with swc 72 | const key = Object.keys(jestConfig.transform)[0]; 73 | // TODO find a way to pass options directly to the plugin without having to use a .swcrc 74 | jestConfig.transform[key] = [ 75 | require.resolve('@swc/jest'), 76 | swcConfig 77 | ? swcConfig 78 | : { 79 | sourceMaps: true, 80 | jsc: { 81 | target: 'es2021', 82 | transform: { 83 | react: { 84 | runtime: 'automatic', 85 | }, 86 | }, 87 | parser: useTypeScript 88 | ? { 89 | syntax: 'typescript', 90 | tsx: true, 91 | dynamicImport: true, 92 | } 93 | : { 94 | syntax: 'ecmascript', 95 | jsx: true, 96 | dynamicImport: true, 97 | }, 98 | }, 99 | }, 100 | ]; 101 | 102 | return jestConfig; 103 | }, 104 | }; 105 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "packages/**" 3 | - "examples/**" 4 | --------------------------------------------------------------------------------