Are separate instances of a class created when it is imported into different entry-point files of webpack? I need to import a class called AJAX
and maintain the same instance throughout the project across all entry-point files.
Currently, AJAX
is used as a global object, but I want to export it as a module in the form of a class or object, while still maintaining the same instance in all files. You can find more information about the AJAX object here.
In my webpack config file, I have two different files emitting, each importing the AJAX object.
entry: {
db_search_new: './js/src/db_search.js',
tbl_structure_new: './js/src/tbl_structure.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'js/dist'),
publicPath: 'http://localhost:3007/js/dist'
},
How can I achieve this using javascript modules? Any suggestions on implementing singletons in JavaScript?