我試圖在我的測試應用程序中使用jQuery驗證插件webpack
,當我在我的文件中import
我得到這個錯誤$(...).validate is not a function
。
我知道jquery-validation
基於IIFE和要求jquery在全球範圍內,我已經暴露我的配置。
這裏自我:
{
entry: {
app: "./assets/js/app.jsx"
},
output: {
path: path.join(__dirname, "/build/js"),
publicPath: "/build/js",
filename: "[name].bundle.js"
},
resolve: {
modulesDirectories: ["node_modules", "bower_components"],
alias: {
"jquery": "jquery/dist/jquery.min",
"jquery.validate": "jquery-validation/dist/jquery.validate"
},
extensions: ["", ".js", ".jsx", ".es6"]
},
amd: {
jQuery: true
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel"
},
{
test: /jquery.validate/,
include: /node_modules/,
loader: "imports?jQuery=jquery"
}
]
},
plugins: [
new webpack.ProvidePlugin({
"$": "jquery",
"jQuery": "jquery"
})
],
devtool: "source-map"
}
,並用它喜歡:
import "jquery.validate"
$("#test").validate();
附:看起來像jQuery驗證插件試圖使用自己的jQuery實例,我想通過比較我的文件[jquery: "3.1.0"]
中的$.fn
和驗證插件[jquery: "2.2.4"]
的內部IIFE,但如何塞住它來使用我的版本?
任何幫助,將不勝感激。
你jqury.js文件之前或jquery.js和文件後添加jqury.validate.js文件? –
'在新的webpack.ProvidePlugin({})'實例中提供了作爲全局webpack配置的jquery',所以它已經有 – Smile0ff