-1

I have a legacy symfony project, i want to migrate slowly to webpack, in the documentation it said that we need to include jquery like that

Encore
// you can use this method to provide other common global variables,
// such as '_' for the 'underscore' library
.autoProvideVariables({
    $: 'jquery',
    jQuery: 'jquery',
    'window.jQuery': 'jquery',
})

The problem is that version of jquery loaded is always 3 but in my legacy project i need the version 2 of jquery. How can i define the version of jquery to load ?

1 Answers1

0

According to this answer install jquery 2.1.1 you can :

  • either change the version number in your package.json file like
{
    "devDependencies": {
        "@symfony/webpack-encore": "^0.22.0",
        "jquery": "2.2.4",
        "webpack-notifier": "^1.6.0"
    },
    ...
    ...
}

And install with the following command :

npm install
  • either install directly with the following commande in your project directory :
npm install jquery@2.2.4 --save-dev

And then in webpack config, you can have this following configuration example :

var Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('public/build/')
    .setPublicPath('/build')

    //.setManifestKeyPrefix('build/')

    .addEntry('app', './assets/js/app.js')
    .splitEntryChunks()
    .enableSingleRuntimeChunk()
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    .enableVersioning(Encore.isProduction())

    // uncomment if you're having problems with a jQuery plugin
    .autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();

This is an attempt of solution.

William Bridge
  • 571
  • 3
  • 12