Waqas Qureshi
Waqas Qureshi

Reputation: 55

After running 'npm start' command project is compiling correctly but not creating assets folder with bundle.js?

I am working on a new project on react js using lynda "Reactjs essential training". Issue is when i run "npm start" command it compiles my project successfully but neither "assets" directory created nor "bundle.js" created why?

I have used my modified "webpack.config.js" what was different from the training exercise files as the provided file not working for me. Below is the code:

.babelrc
--------
{
"presets": ["@babel/preset-env","@babel/react"]
}

package.json
------------
{
"name": "react-essential",
"version": "1.0.0",
"description": "A project focusing on React and related tools",
"main": "index.js",
"dependencies": {
"@babel/preset-react": "^7.0.0",
"babel-cli": "^6.26.0",
"babel-preset-latest": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.4",
"babel-preset-react-native": "^5",
"webpack": "^4.28.3",
"webpack-cli": "^3.1.2",
 "webpack-dev-server": "^3.1.14"
},
"scripts": {
"start": "./node_modules/.bin/webpack-dev-server"
},
"author": "Muhammad Waqas",
"license": "MIT"
}

webpack.config.js
-----------------
var webpack = require("webpack");
module.exports = {
entry: __dirname + "/src/index.js",
output: {
    path: __dirname + "/dist/assets",
    filename: "bundle.js",
    publicPath: "assets"
},
devServer: {
    inline: true,
    contentBase: __dirname + "/dist",
    port: 3000
},
module: {
    rules: [{
        test: /\.js$/,
        loader: ["babel-loader"]
    }]
}
}

Whenever i run "npm start" it should start the webpack-dev-server and changes (if any) should be reflected in the browser.

Upvotes: 0

Views: 2753

Answers (2)

Harrison Ifeanyichukwu
Harrison Ifeanyichukwu

Reputation: 292

webpack development server does not write to disk. it serves from memory. if you wish to create a production build, that will get outputted to the assets folder, you need to add a build script, which you will run.

Add the follow build script to your package.json file, just after the start script, the order does not matter though:

"start": "./node_modules/.bin/webpack-dev-server", "build": "./node_modules/.bin/webpack --config webpack.config.js",

Then you can run the following on the command line, to create a build

npm run build

just like running

npm run start

Upvotes: 1

Andy Ray
Andy Ray

Reputation: 32076

The webpack dev server doesn't write any assets to disk. It serves them all from memory.

Upvotes: 0

Related Questions