<link rel="icon" href="./favicon.ico" />
Next, add a <script>
tag pointing at src/index.js
to public/index.html
. It should be placed just before the closing </body>
element.
<!-- ... -->
<script type="module" src="../src/index.js"></script>
</body>
</html>
If you use Create React App's svg component import feature, add @parcel/transformer-svg-react
to your .parcelrc
following these instructions.
{
"extends": "@parcel/config-default",
"transformers": {
"jsx:*.svg": ["...", "@parcel/transformer-svg-react"],
"jsx:*": ["..."]
}
}
Then, convert import statements to use the jsx:
prefix:
import { ReactComponent as Logo } from './logo.svg';
import Logo from 'jsx:./logo.svg';
Importing SVGs without the jsx:
prefix will return a URL instead of a component, just like in Create React App.
If you use Create React App's GraphQL import feature, or other Babel Macros, you'll need to add babel-plugin-macros
to a babel.config.json
config file.
{
"plugins": ["babel-plugin-macros"]
}
Parcel includes support for other JavaScript transpilation features (e.g. JSX, TypeScript, and Preset Env) out of the box, so they are not needed in your Babel config file. See the documentation for more information.
Parcel includes support for CSS, CSS modules, SASS, and autoprefixing out of the box. If you use the @import-normalize feature of Create React App, you'll need to add postcss-normalize
to your .postcssrc
configuration.
{
"plugins": ["postcss-normalize"]
}
Additionally, if you use Tailwind CSS, you'll need to add the tailwindcss
plugin to .postcssrc
as well. See the documentation for more details.
Next, you'll need to update the "test"
script to run Jest directly. First, install the required dependencies:
npm install jest jest-watch-typeahead babel-jest babel-preset-react-app identity-obj-proxy --save-dev
Then, update the "test"
script in your package.json
:
{
"scripts": {
"test": "react-scripts test"
}
}
{
"scripts": {
"test": "jest"
}
}
Now create the following files:
{
"roots": ["<rootDir>/src"],
"collectCoverageFrom": ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
"setupFilesAfterEnv": ["<rootDir>/src/setupTests.js"],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
],
"testEnvironment": "jsdom",
"transform": {
"^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": "<rootDir>/config/jest/babelTransform.js",
"^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$",
"^.+\\.module\\.(css|sass|scss)$"
],
"modulePaths": [],
"moduleNameMapper": {
"^react-native$": "react-native-web",
"^.+\\.(css|sass|scss)$": "identity-obj-proxy",
"^jsx:.+\\.svg": "<rootDir>/config/jest/SvgComponent.js"
},
"moduleFileExtensions": ["web.js", "js", "web.ts", "ts", "web.tsx", "tsx", "json", "web.jsx", "jsx", "node"],
"watchPlugins": [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname"
],
"resetMocks": true
}
const babelJest = require('babel-jest').default;
module.exports = babelJest.createTransformer({
presets: [
[
require.resolve('babel-preset-react-app'),
{
runtime: 'automatic'
},
],
],
babelrc: false,
configFile: false,
});
const path = require('path').default;
module.exports = {
process(src, filename) {
const assetFilename = JSON.stringify(path.basename(filename));
return `module.exports = ${assetFilename};`;
},
};
export function SvgComponent() {
return null;
}
Create React App uses Eslint to lint your code. Parcel does not include linting by default, but you can setup a separate npm script in your package.json
to run it.
First, install the required dependencies:
npm install eslint eslint-config-react-app --save-dev
Then, add a "lint"
script to your package.json:
{
"scripts": {
"lint": "eslint src"
}
}
To run the linter, run npm run lint
.
Add the following files to your .gitignore
file:
.parcel-cache
dist
That's it! Now you can start the dev server with npm start
. As it builds your app for the first time, Parcel may install additional plugins and dependencies it needs.
If you run into any issues during this process, please file an issue on Github.