Answer the question
In order to leave comments, you need to log in
How to import jQuery plugin when using webpack, but load jQuery from CDN?
In general, I want to use the jQuery plugin, but since I'm going to use the final js file in wordpress, I want to load jQuery itself from the CDN.
I have this webpack config:
module.exports = {
mode: 'development',
entry: './src/js/entry.js',
output: {
filename: 'index.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: [
['env', {modules: false}],
],
},
},
],
},
devtool: 'source-map'<code></code>
};
import './vendor/magnific-popup';
ERROR in ./src/js/vendor/magnific-popup.js
Module not found: Error: Can't resolve 'jquery' in '...\src\js\vendor'
@ ./src/js/vendor/magnific-popup.js 6:46-67
@ ./src/js/entry.js
Answer the question
In order to leave comments, you need to log in
Include jQuery in the old-fashioned way in html, specify in the webpack config
externals: {
jquery: 'jQuery'
}
import $ from 'jquery';
$('.block').html('Ура, jQuery с нами!');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question