To generate optimized source code with or without a source map for production use, you'll need to adjust your build configuration based on your environment (production vs development). Here's how you can handle this with Webpack:
For Production (Minimized and Optimized Code):
In your Webpack configuration, set the mode to production, which automatically optimizes the code (minification, dead code elimination via tree shaking).
You can disable source maps in production to avoid exposing your code, or generate a minimized version of them using source-map as the devtool.
Example for webpack.prod.js:
module.exports = {
mode: 'production',
devtool: 'source-map', // Generates a separate source map for debugging
};
For Development (Better Debugging with Source Maps):
Set the mode to development and use inline-source-map to enable more detailed debugging.
Example for webpack.dev.js:
module.exports = {
mode: 'development',
devtool: 'inline-source-map', // Provides better source maps for debugging
};