Set up Your Local Environment
Step 1: Set up Your Local Environment
Start by setting up your local development environment.
Install Node
For this tutorial, you need Node.js version 18+. To check your version of Node.js, run the following command in your terminal:
If you do not have Node.js installed, you can download it from nodejs.org (downloads).
Set up a project directory
-
Create a new project directory.
-
Navigate to the directory using the terminal.
Generate a package.json file
Node.js version and custom dependencies
- Make sure that you are using Node.js version 18+ and npm version 8+.
- This sample app uses custom dependencies and does not rely on the
create-next-appCLI tool.
- To create the project’s
package.jsonfile, enter the interactive initialization sequence. Run the following command in the terminal:
Press enter to continue prompts.
To write a package.json file with default values, run npm init -y instead. Descriptive fields will be blank.
Install npm packages
- Install
big-design,big-design-icons,big-design-theme,dotenv,next,react,react-dom, andstyled-components.
- Install dev dependencies.
babel-plugin-styled-components is a supplement to the styled-components library that, among other things, offers improved debugging and minification of styles.
@types/node and @types/react contain TypeScript type definitions for Node.js and React.js respectively.
View tested package versions
You can view a list of all the tested package versions in the package.json file on the Step 1 branch of this sample app’s repo.
Add scripts
-
Open
package.jsonin your text editor. -
Update the
scriptsproperty, by adding thedev,build, andstartscripts.
- Save your changes.
Add the node and npm engines
-
Open
package.jsonin your text editor. -
Add an
enginesproperty with the following values:
- Save your changes.
Create a starter page
-
In the root directory of your project, create a
pagesfolder. -
In the
pagesfolder, create anindex.tsxfile. This is your app’s homepage. -
Open
index.tsxin your code editor. -
Add
PanelandTextBigDesign imports at the top of the file.
The Panel component allows you to contain content in a structured format. To learn more about the BigDesign’s Panel component, see Panel Developer Docs.
Text is one of the many predefined typography components in BigDesign. BigDesign offers multiple properties to customize the typographic palette. To view available typography components, see Typography.
- Add the
Indexfunctional component below the import statements. You can view index.tsx (GitHub).
Next.js associates each file in the pages folder with a route based on the file’s name. Consequently, the Index React component you exported in pages/index.tsx will be accessible at /index.
Initialize BigDesign
Next.js allows you to use a theme provider and import CSS files from node_modules. In this tutorial, you integrate BigDesign React components to give your app a distinct BigCommerce look and feel.
-
Next.js uses the
Appcomponent to initialize pages. To override the defaultAppcomponent, add the_app.tsxfile to thepagesfolder. This is where you initialize BigDesign. -
Open
_app.tsxand importGlobalStylesfrom BigDesign andAppPropsfrom Next.js.
Importing the GlobalStyles component will set BigCommerce’s base styles globally.
- Add the
MyAppfunctional component below the import statements. You can view _app.tsx (GitHub).
The Component prop represents the active page. Consequently, it will change when you navigate between routes.
Initialize styled-components
Because BigDesign uses styled-components, we need to add additional configuration for both BigDesign and styled-components to function properly.
-
Add a custom
_document.tsxfile to your pages folder. -
Import
DocumentandDocumentContext, the built-in TypeScript types, from Next.js.
- Import
ServerStyleSheetfrom styled-components.
- Extend the
Documentclass. You can view _document.tsx (GitHub).
Start the development server
- Using the terminal, open the root directory of your app and start the development server.
- Open
http://localhost:3000from your browser. You should see the text “Hello world” displayed under Homepage.
