I have this error on frontend:
Uncaught ReferenceError: $ is not defined
This is after I have tried bundling all js files (including jQuery) in a folder into 1 file with:
var glob = require("glob");
module.exports = {
entry: {
bundle: glob.sync("./src/js/*.js")
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist/js")
},
There is no error when building.
Does bundling jQuery need some sort of unique approach?
Or if this relates to the "order" of the files bundled, I thought webpack was able to overcome this by design?
Edit:
I abandoned this approach of using glob
, instead opting to go for a single entry file that has import statements for third party js libraries and jQuery plugins, eg:
entry_file.js:
import hljs from './highlight';
import $ from './jquery';
webpack.config.js:
module.exports = {
entry: "./src/js/entry_file.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist/js")
},
This new approach is not without its own headaches, however, as some plugins/libraries have their own idiosyncrasies and throw errors like Uncaught ReferenceError: jQuery is not defined
etc.