Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ jobs:

- name: Compile create-react-app examples using react-scripts
run: |
yarn workspaces foreach --include "with-javascript" run build-react-scripts
yarn workspaces foreach --include "with-typescript" run build-react-scripts
yarn workspaces foreach --include "with-*" run build-react-scripts

- name: Test create-react-app examples using react-scripts
run: |
yarn workspaces foreach --include "with-javascript" run test-react-scripts
yarn workspaces foreach --include "with-typescript" run test-react-scripts
yarn workspaces foreach --include "with-*" run test-react-scripts

test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -70,10 +68,8 @@ jobs:

- name: Compile create-react-app examples using craco
run: |
yarn workspaces foreach --include "with-javascript" run build
yarn workspaces foreach --include "with-typescript" run build
yarn workspaces foreach --include "with-*" run build

- name: Test create-react-app examples using craco
run: |
yarn workspaces foreach --include "with-javascript" run test
yarn workspaces foreach --include "with-typescript" run test
yarn workspaces foreach --include "with-*" run test
19 changes: 0 additions & 19 deletions .versionrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
const exampleUpdater = {
readVersion: (contents) => {
return JSON.parse(contents).dependencies['craco-esbuild'];
},
writeVersion: (contents, version) => {
const json = JSON.parse(contents);
json.dependencies['craco-esbuild'] = version;
return JSON.stringify(json);
},
};

module.exports = {
// Where we read the current version
packageFiles: 'packages/craco-esbuild/package.json',
Expand All @@ -18,14 +7,6 @@ module.exports = {
filename: 'packages/craco-esbuild/package.json',
type: 'json',
},
{
filename: 'examples/with-javascript/package.json',
updater: exampleUpdater,
},
{
filename: 'examples/with-typescript/package.json',
updater: exampleUpdater,
},
],
scripts: {
postbump: 'yarn && git add yarn.lock && yarn prettier',
Expand Down
2 changes: 1 addition & 1 deletion examples/with-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
"craco-esbuild": "0.2.1",
"craco-esbuild": "workspace:packages/craco-esbuild",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2"
Expand Down
23 changes: 23 additions & 0 deletions examples/with-svgr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
12 changes: 12 additions & 0 deletions examples/with-svgr/craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const CracoEsbuildPlugin = require('craco-esbuild');

module.exports = {
plugins: [
{
plugin: CracoEsbuildPlugin,
options: {
enableSvgr: true,
},
},
],
};
42 changes: 42 additions & 0 deletions examples/with-svgr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "with-svgr",
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "6.1.1",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
"craco-esbuild": "workspace:packages/craco-esbuild",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2"
},
"scripts": {
"start": "craco start",
"start-react-scripts": "react-scripts start",
"build": "craco build",
"build-react-scripts": "react-scripts build",
"test": "craco test",
"test-react-scripts": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added examples/with-svgr/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions examples/with-svgr/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added examples/with-svgr/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/with-svgr/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/with-svgr/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions examples/with-svgr/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
38 changes: 38 additions & 0 deletions examples/with-svgr/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
26 changes: 26 additions & 0 deletions examples/with-svgr/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { ReactComponent as Logo } from './logo.svg';
import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<Logo />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}

export default App;
9 changes: 9 additions & 0 deletions examples/with-svgr/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
13 changes: 13 additions & 0 deletions examples/with-svgr/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
11 changes: 11 additions & 0 deletions examples/with-svgr/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
1 change: 1 addition & 0 deletions examples/with-svgr/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/with-svgr/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
2 changes: 1 addition & 1 deletion examples/with-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/node": "^14.14.25",
"@types/react": "^17.0.1",
"@types/react-dom": "^17.0.0",
"craco-esbuild": "0.2.1",
"craco-esbuild": "workspace:packages/craco-esbuild",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/craco-esbuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ You can configure the options of the plugin by passing an `options` object.

- `esbuildLoaderOptions`: customise the options passed down to the `esbuild` loader. _Note: This will be used only by webpack_
- `includePaths`: include external directories in loader.
- `enableSvgr`: enable the svgr webpack plugin. SVGs are loaded as separate files by default. Enabling this options allow you to import SVGs as React components. See [CRA documentation](https://create-react-app.dev/docs/adding-images-fonts-and-files/#adding-svgs) for more detailed explanation.

For example add this configuration to your `craco.config.js` configuration file:

Expand All @@ -68,6 +69,7 @@ module.exports = {
plugin: CracoEsbuildPlugin,
options: {
includePaths: ['/external/dir/with/components'], // Optional. If you want to include components which are not in src folder
enableSvgr: true, // Optional.
esbuildLoaderOptions: {
loader: 'jsx',
target: 'es2015',
Expand Down
5 changes: 3 additions & 2 deletions packages/craco-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"src"
],
"peerDependencies": {
"@craco/craco": "^5.5.0",
"react-scripts": "^3.3.0"
"@craco/craco": "^5.5.0 || ^6.0.0",
"react-scripts": "^3.3.0 || ^4.0.0"
},
"dependencies": {
"@svgr/webpack": "^5.5.0",
"esbuild-jest": "0.5.0",
"esbuild-loader": "^2.9.2"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/craco-esbuild/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ module.exports = {
const esbuildLoaderOptions =
pluginOptions && pluginOptions.esbuildLoaderOptions;

/**
* Enable the svgr plugin
* svg will not be loaded as a file anymore
*/
if (pluginOptions && pluginOptions.enableSvgr) {
webpackConfig.module.rules.unshift({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
}

// add includePaths custom option, for including files/components in other folders than src
// Used as in addition to paths.appSrc, optional parameter.
const optionalIncludes =
Expand Down
Loading