Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

smikhalevski/single-module-instance-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Single Module Instance Webpack Plugin

npm version

At runtime webpacked module can be initialized more than once which is expected behavior for Node. Nevertheless this behavior hurts a lot if you are used to RequireJS and even may introduce unexpected singleton collisions.

SingleModuleInstanceWebpackPlugin plugin along with DedupePlugin would force require to serve only one instance of each requested module.

Update webpack.config.js with following snippet:

var SingleModuleInstancePlugin = require('single-module-instance-webpack-plugin');

module.exports = {
  plugins: [
    new webpack.optimize.DedupePlugin(),
    new SingleModuleInstancePlugin()
  ]
}

TODO

  • Add tests

License

The code is available under MIT licence.

About

Webpack plugin that forces require to return same instance of module regardless the place where import occurs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published