score:217

Accepted answer

create-react-app has a very interesting setup.

i started digging in the package.json npm script start

"start": "react-scripts start"

that takes me to their binary react-scripts under node_modules/.bin
i'll post the relevant stuff here.

switch (script) {
  case 'build':
  case 'eject':
  case 'start':
  case 'test': {
    const result = spawn.sync(
      'node',
      [require.resolve('../scripts/' + script)].concat(args),
      { stdio: 'inherit' }
    );

so this tells me that they are looking for script inside ../scripts/ folder.

so i go to the react-scripts npm module(node_modules/react-scripts) and open up the node_modules/react-scripts/scripts/start.js file since i was doing npm start.

now here is where i found the webpack config i was looking for.
they were specifically referring to node_modules/react-scripts/config/webpack.config.dev.js. i'll post the relevant stuff here.

entry: [
  // finally, this is your app's code:
  paths.appindexjs,
],
plugins: [
  // generates an `index.html` file with the <script> injected.
  new htmlwebpackplugin({
    inject: true,
    template: paths.apphtml,
  }),

so file referred by paths.appindexjs is the entry file in the webpack config.

and they are using htmlwebpackplugin to load the html at the path paths.apphtml.

final piece of the puzzle is linking this back to the files you posted. posting relevant stuff from paths.js

const appdirectory = fs.realpathsync(process.cwd());
const resolveapp = relativepath => path.resolve(appdirectory, relativepath);
module.exports = {
  ...
  apphtml: resolveapp('public/index.html'),
  appindexjs: resolveapp('src/index.js'),
  ...
}

so inside your application directory,
apphtml is file public/index.html
appindexjs is file src/index.js

your two files in question.
wow! that was quite a journey..:p


update 1 - as of react-scripts@3.x

the react-scripts binary under node_modules/.bin has changed the logic as below. essentially doing the same thing.

if (['build', 'eject', 'start', 'test'].includes(script)) {
  const result = spawn.sync(
    'node',
    nodeargs
      .concat(require.resolve('../scripts/' + script))
      .concat(args.slice(scriptindex + 1)),
    { stdio: 'inherit' }
  );

the webpack configs for dev & prod has been combined into one.
const configfactory = require('../config/webpack.config');

the htmlwebpackplugin config looks like this - this is since they have to conditionally add production config on top of this

plugins: [
  // generates an `index.html` file with the <script> injected.
  new htmlwebpackplugin(
    object.assign(
      {},
      {
        inject: true,
        template: paths.apphtml,
      },

the paths file code has some updates

module.exports = {
  ...
  apphtml: resolveapp('public/index.html'),
  appindexjs: resolvemodule(resolveapp, 'src/index'),
  ...
};

Related Query

More Query from same tag