Could not find a production build next 1

Could not find a production build next

# First run
npm run build

# then
npm run start

Here is what the above code is Doing:
1. We’re using the `npm run` command to run a script that we’ve defined in our `package.json` file.
2. The `build` script is defined in our `package.json` file as `webpack –config webpack.config.js`.
3. The `start` script is defined in our `package.json` file as `webpack-dev-server –config webpack.config.js`.

The `build` script will run Webpack and create a `bundle.js` file in our `dist` folder.
The `start` script will run Webpack in watch mode and serve our application at `http://localhost:8080`.

## Step 3: Add a `webpack.config.js` file

Create a `webpack.config.js` file in the root of your project.

“`js
// webpack.config.js
const path = require(‘path’);

module.exports = {
entry: ‘./src/index.js’,
output: {
filename: ‘bundle.js’,
path: path.resolve(__dirname, ‘dist’)
}
};
“`

Here’s what the above code is doing:
1. We’re using the `path` module to get the absolute path of the `dist` folder.
2. We’re telling Webpack that our application’s entry point is `./src/index.js`.
3. We’re telling Webpack that the output file should be `bundle.js` and it should be placed in the `dist` folder.

## Step 4: Add a `src/index.js` file

Create a `src` folder in the root of your project.
Create an `index.js` file in the `src` folder.

“`js
// src/index.js
console.log(‘Hello, world!’);
“`

## Step 5: Run the application

Run the following command in your terminal:

“`sh
npm run build
“`

You should see a `bundle.js` file in your `dist` folder.

Run the following command in your terminal:

“`sh
npm run start
“`

You should see the following output in your terminal:

“`sh
Project is running at http://localhost:8080/
webpack output is served from /
“`

Open your browser and navigate to `http://localhost:8080`.
You should see the following output in your browser’s console:

“`sh
Hello, world!
“`

## Step 6: Add a `src/index.html` file

Create an `index.html` file in the `src` folder.

“`html





Hello, world!





“`

## Step 7: Add a `src/index.css` file

Create an `index.css` file in the `src` folder.

“`css
/* src/index.css */
body {
background-color: #fafafa;
}
“`

## Step 8: Add a `src/index.js` file

Update the `src/index.js` file.

Similar Posts