score:217
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'),
...
};
Source: stackoverflow.com
Related Query
- How React JS index.js file contacting index.html for id references?
- How can I render HTML from another file in a React component?
- How do I configure my .htaccess file for React App in Subdirectory?
- how to import HTML file into React component and use it as a component?
- How to use one vendor chunk file (webpack) for multiple react projects
- React how to connect JS file with HTML file
- In React Typescript how to define type for ...rest parameter for native html elements?
- How to link/reference multiple scripts in an html file with react (WITHOUT NODE.js)?
- How to import react modules from an HTML file with no npm/webpack
- How to import html file into react as string?
- How to add emmet support for .mdx / markdown react file types in vscode
- How to move react event handlers to separate file ,export and then import for reuse in multiple different functional components?
- How to pass data from blade.php file to a react component using HTML element attributes?
- How can I create a configuration file for react and prevent webpack bundling it?
- How to get the file length for an file in react js
- How to translate a tsx file to a js file for React
- How to apply CSS style to HTML file that is inside the public folder of React JS
- How to configure app.yaml file for node react project in google app engine
- How I access process.env variables in react html file
- How to write Definition File for React JSX
- how to update html content dynamicaly with for loop in react js javascript
- how I can get the geoJson file for gall-peters world map for react leaflet
- How to read local html file content inside React js App using Webpack loaders?
- how to import css file in react when generating static html and inject imported css into html head tag?
- How to think in React for this example: Should I store repetitive html markup in an Array and import it into a class component?
- How can you make a conditional external script reference in the public html file in reactjs. i.e. one for production and one for staging
- How to output array with keys to my html file from promise function using React
- how to write hover in same class in css file for react js
- How to convert this.state with index for React Hooks API
- How to import external html file to React app?
More Query from same tag
- "this.props" not working in my on mouseup event function in Map Component using react and mapbox-gl
- Datatables.net Server-Side pagination with Spring: How to select single row's ID?
- React npm run build, what is that, why we need that?
- CSS grid cells are not square
- Bootstrap tooltip is not working with react.js
- react fails to inline change the background color of a button
- Add Favicon with React and Webpack
- React router is not taking ID in Link
- React render() without html tags?
- Unable to send multipart/form-data with REACT to MySQL
- Appending HTML to component and React Component class unexpected token, expected }
- Get the input value in React hooks and print it
- How do I render HTMLDocument type in React render
- If and why the CSS should be put outside the react function components(near the imports)?
- Mixed Content with heroku server
- How to make a drop-down menu appear exactly below the bar in Material-UI?
- ReactJS | Map through nested objects
- how to change the coreUi logo in Free React.js Admin Template of sidebar and header?
- How to place the popup based on the position of another div element using javascript and react?
- React html characters inside input placeholder
- React component loops updating (GraphQL)
- Material UI sub drawer from main drawer
- Why reducer function return only proxy? redux/toolkit
- Require class from another file in ReactJS
- Not able to render React Component to many times
- React Promise asynchronous tasks order not correct
- Rendering components using .map resets setTimeout within components
- Select a document within the db.collection operation
- How to create a react component from a DOM node?
- react bootstrap modal - how do I get it to show?