jquery-ui Datepicker 小部件无法与 Encore webpack 一起使用,因为它不是一个函数:
TypeError: $(...).datepicker is not a function
Run Code Online (Sandbox Code Playgroud)
这是我的 app.js:
global.$ = global.jQuery = $;
require('jquery-ui');
require('popper.js');
require('bootstrap');
require('bootstrap-table');
require('select2');
require('../lib/jquery-switchbutton/jquery.switchButton.js');
require('./bootstrap3-typeahead.min.js');
Run Code Online (Sandbox Code Playgroud)
和 webpack 配置:
var Encore = require('@symfony/webpack-encore');
var path = require('path');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.splitEntryChunks()
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.autoProvideVariables({
$: "jquery",
jQuery: "jquery",
Popper: ['popper.js', 'default']
});
var config = Encore.getWebpackConfig();
config.resolve.alias = {
jquery: path.join(__dirname, 'node_modules/jquery/dist/jquery')
};
module.exports = config;
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?谢谢!