将jquery-mobile与Webpack一起使用

自由

我正在尝试使用webpack加载jquery-mobile,到目前为止还没有运气。我知道jquery-mobile取决于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。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章