How do I bundle with webpack?
See original GitHub issueI have a site that already have jquery 1.7 loaded.
I want to bundle my dependencies with webpack.
I’m tried
import “select2” require “select2”
my webpack config looks like this:
module.exports = {
mode: "development",
entry: {
frb: "./src/app/loader.js"
},
output: {
path: path.resolve(__dirname, "./src/lib"),
filename: "bundle.js"
},
module: {
rules: [
// { parser: { amd: false } },
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: "babel-loader",
query: {
presets: [
[
"@babel/preset-env",
{
targets: {
chrome: "58",
ie: "9"
}
}
]
]
}
}
]
},
externals: {
$: "jquery",
jQuery: "jquery"
},
plugins: [
// Ignore all locale files of moment.js
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
};
I just keep getting : TypeError: $(...).select2 is not a function
Am I missing something?
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Getting Started - webpack
Learn how to bundle a JavaScript application with webpack 5. ... First let's create a directory, initialize npm, install webpack locally, ...
Read more >How to Bundle a Simple Static Site Using Webpack - SitePoint
Add the following to app.js : require('./main.js');. And change the webpack config thus: entry: './src/js/app.js',. Run npm run build again to ...
Read more >How to Bundle an Application with Webpack - Sweetcode.io
Webpack takes your Javascript files, dependencies as input, bundles them, and then outputs compressed optimised files. It then constructs a dependency graph for ......
Read more >Webpack: How It Generates the Bundle - Encora
Bundle. File that contains all the modules your application needs. In other words, it is how the application is packaged. Dependency Graph. When ......
Read more >Module Bundling with Webpack: Getting Started Guide
Module bundlers are just what they are called, they bundle up JavaScript modules into one file. This way, when the client makes a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe it would be an improvement to the documentation to add an up to date version of the installation. People will answer this question a lot, since there is no common example.
I managed to get this to work in Typescript + webpack kind of (though I’m not sure if it’s the right approach).
dropdown.ts
@types/select2-module.d.ts
I also had to remove the dependency on
requirejs
from the DefinitelyTyped types because it conflicted with another require type, but that’s kind of specific to my project I think.Hopefully a similar approach helps with other non-typescript webpack bundling. I think the important part might be to explicitly bind with the
select2($)
.