【问题标题】:Jquery define version in webpack symfony encoreJquery 在 webpack symfony encore 中定义版本
【发布时间】:2019-03-08 11:40:49
【问题描述】:

我有一个遗留的 symfony 项目,我想慢慢迁移到 webpack,在documentation 中说我们需要像这样包含 jquery

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',
})

问题是加载的 jquery 版本始终为 3,但在我的旧项目中,我需要 jquery 的版本 2。 如何定义要加载的 jquery 版本?

【问题讨论】:

    标签: jquery symfony webpack-encore


    【解决方案1】:

    根据这个答案install jquery 2.1.1 你可以:

    • 要么更改 package.json 文件中的版本号,例如
    {
        "devDependencies": {
            "@symfony/webpack-encore": "^0.22.0",
            "jquery": "2.2.4",
            "webpack-notifier": "^1.6.0"
        },
        ...
        ...
    }
    

    并使用以下命令安装:

    npm install
    
    • 在您的项目目录中使用以下命令直接安装:
    npm install jquery@2.2.4 --save-dev
    

    然后在 webpack 配置中,你可以有以下配置示例:

    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();
    

    这是一个解决方案的尝试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-14
      • 2020-10-27
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 2021-03-23
      • 2020-01-29
      相关资源
      最近更新 更多