我正在尝试迁移一个旧项目以使用.我写了一些自定义插件,不再工作。虽然我认为这个问题应该发生在其他人身上,但我找不到任何关于它的帖子。webpack
这是我包含:base.js
(function ($) {
$.fn.my_extension = function () {
alert("I am found!");
};
}(jQuery));
这就是我在模板中使用它的方式:
<script type="text/javascript">
$(document).ready(function() {
$('#my-id').my_extension();
});
</script>
这是我在我的包含:index.js
// JS Dependencies
import 'jquery';
...
// Custom JS
import '../js/base.js';
这是我的:webpack.config.js
var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
module.exports = {
context: __dirname,
mode: 'development',
entry: './static/js/index.js',
output: {
path: path.resolve('./static/webpack_bundles/'),
filename: "[name]-[hash].js"
},
module: {
rules: [
{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
}, {
loader: 'expose-loader',
options: '$'
}]
},
...
],
},
plugins: [
new BundleTracker({filename: 'webpack-stats.json'}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
'window.jQuery': 'jquery'
})]
}
这是我在调用模板时遇到的错误:
类型错误: $(...).my_extension不是函数
任何想法,我可能做错了什么?
翻翻过去那场雪
相关分类