I am writing my own css/js components library and decided to pack it using webpack 3. And some of the components require JQuery. So I want webpack to include JQuery from npm inside the development bundle, to easily test and develop, but I want webpack to exclude it from the production bundle and use global JQuery from the window object instead. Moreover, only a few components require JQuery, so I want to make user of the library to add JQuery if he doesn't want to use this few components. Is it possible to do with webpack and how?
1 Answer
Read about webpack shimming modules.https://webpack.github.io/docs/shimming-modules.html
Here what i am doing. $ will be available in every module without import or require.
plugins: [
new webpack.ProvidePlugin({
$: path.resolve(__dirname, "libs/jquery-3.2.1.min.js")
})
]