簡體   English   中英

在Webpack中使用jquery-mobile

[英]Using jquery-mobile with Webpack

我試圖使用webpack加載jquery-mobile到目前為止沒有運氣。 我知道jquery-mobile依賴於jquery-ui,而jquery-ui又依賴於jquery。

如何在Webpack中設置這樣的場景?

這是我的webpack.config.js

var webpack = require('webpack');
var path = require('path');
var bower_dir = __dirname + '/bower_components';

module.exports = {

    context: __dirname,
    entry: './assets/js/index.js',         
    output: {
        path: path.resolve('./assets/bundles/'),
        filename: "[name]-[hash].js",
    },
    plugins: [
        new BundleTracker({filename: './webpack-stats.json'}),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery'
        })
    ],
    module: {
        loaders: [
            {test: /[\/\\]node_modules[\/\\]some-module[\/\\]index\.js$/, loader: "imports?this=>window"}
        ]
    },
    resolve: {
        alias: {
            'jquery': bower_dir + '/jquery/src/jquery.js',
            'jquery-ui': bower_dir + '/jquery-ui/jquery-ui.js',
            'jquery-mobile': bower_dir + '/jquery-mobile/js/jquery.mobile.js'
        }
    }
};

任何幫助將非常感激。

謝謝大家。

如果您只是按正確的順序將所需的腳本添加到頁面中,則無需在webpack中擔心。

您所要做的就是告訴webpack這些模塊是從外部引用加載的,如下所示:

{
  externals: {
    'jquery': 'jQuery'
  } 
}

這告訴webpack每次需要('jquery')它將返回一個全局可用的變量jQuery。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM