A project I'm working needs a third party javascript snippet which has a dependency on the 'full' jQuery framework. Shopware (/bootstrap 4) currently ships with jQuery out of the box, but is using the Slim (and not full) version of it.
Is there a way to upgrade/change the used jQuery version?
CodePudding user response:
In your plugin create a webpack.config.js
the directory structure should look something like this:
├── MyPlugin
│ └── src
│ └── Resources
│ └── app
│ └── storefront
│ ├── build
│ │ └── webpack.config.js
│ └── src
│ └── main.js
The content of webpack.config.js
:
const { join, resolve } = require('path');
module.exports = () => {
return {
resolve: {
alias: {
'@jqueryNew': resolve(
join(__dirname, '..', 'node_modules', 'jquery'),
),
},
},
};
};
Then within the storefront
directory install the latest version of jquery or whatever specific version you need:
npm install jquery
In your main.js
you can then import the newer jquery package from the resolved alias and set it globally:
import $ from '@jqueryNew';
window.$ = window.jQuery = $;
global.$ = global.jQuery = $;
CodePudding user response:
jQuery will be removed with the next major. It's not future-proof to still use it. You should look for alternatives, it's not so complicated with default javascript