-
-
Save iamakulov/1ef1f0f7cbc5fd4ed89f9cc658364c5e to your computer and use it in GitHub Desktop.
Removing development files from bundle (using NormalModuleReplacementPlugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This import should be dropped in production, | |
// because it's very large and contains development data | |
// (like locales for all languages). | |
import load from './very.large' | |
export const main = () => { | |
let data = {} | |
if (process.env.NODE_ENV !== 'development') { | |
data = load() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default () => 'VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpack = require('webpack'); | |
module.exports = { | |
entry: '...', | |
output: { /* ... */ }, | |
plugins: process.env.NODE_ENV === 'development' ? | |
[] : [ | |
// This will replace every import matching /very\.large\.js$/ with ./very.large.replacement.js | |
// See https://webpack.js.org/plugins/normal-module-replacement-plugin/ | |
new webpack.NormalModuleReplacementPlugin(/very\.large\.js$/, './very.large.replacement.js') | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment