I get the sense that most of your question is actually related to confusion over what minifying code actually means.
Definition
Minification, also known as minimization, is the process of removing all unnecessary characters from JavaScript source code without altering its functionality. This includes the removal of whitespace, comments, and semicolons, along with the use of shorter variable names and functions. Minification of JavaScript code results in compact file size.
Source: Why Minify JavaScript Code?
Applied to Create React App
In your case, the npm run build
command will execute react-scripts build
which is provided by Create React App. The documentation explains what this does:
Builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes. If necessary, classnames and function names can be enabled for profiling purposes. See the production build section for more information.
Source: Create React App: npm run build
When npm run build
is run, it will create a build
folder. Inside ./build/static
you'll typically find your minified code (javascript, css, media, ...).
In ./build/static/js
you'll likely find the following files:
- [hash].chunk.js
- [hash].chunk.js.map
- main.[hash].chunk.js
- main.[hash].chunk.js.map
- runtime-main.[hash].chunk.js
- runtime-main.[hash].chunk.js.map
Note: the exact output will vary on your version of Create React App.
What are Source Maps?
As you'll have noticed above, the build folder contains a *.js.map
file for each .js
file, these are source maps.
The reason these are generated is for debugging purposes.
If you were to try and debug your code using the developer tools of your browser, you'd have a hard time understanding your minified (and possibly uglified code). By adding these .map
-files, your browser can load these (by using an HTTP header) and represent your code as if you were looking at the original code.
You can find more information here: MDN - Use a source map
Developer tools "Inspector"
Every major browser has a way of viewing or debugging your application using "developer tools". These developer tools usually show a version of your code that is modified to be easier to read as a developer.
If you wanted to verify if your HTML code is minified or not, there are 2 things you could check:
- Check your
./build/index.html
file and ensure that only the build
folder is being hosted by your web server
- Instead of using the "Inspector", view the page source instead (usually you can see this via right-click on the page and selecting "View Page Source")