Skip to content

Instantly share code, notes, and snippets.

@iamakulov
Forked from tricoder42/bundle.js
Last active June 23, 2017 17:13
Show Gist options
  • Save iamakulov/1ef1f0f7cbc5fd4ed89f9cc658364c5e to your computer and use it in GitHub Desktop.
Save iamakulov/1ef1f0f7cbc5fd4ed89f9cc658364c5e to your computer and use it in GitHub Desktop.
Removing development files from bundle (using NormalModuleReplacementPlugin)
// 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()
}
}
export default () => 'VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE VERY LARGE'
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