我正在将我的项目移至webpack2并遇到jQuery.initialize
的问题require('jquery');
require('jquery.initialize/jquery.initialize.min.js');
$(document).ready(function () {
// ========================================
// comment editor.
// ========================================
$('.comment-editor textarea[name=content]').initialize(function () {
$(this).froalaEditor({
所以这个froalaEditor调用没有发生。任何想法?
也试过这个
$.initialize('.comment-editor textarea[name=content]', function() {
console.log('test');
});
越来越;
comment.js:13 Uncaught TypeError: $.initialize is not a function
at HTMLDocument.<anonymous> (comment.js:13)
at mightThrow (jquery.js:3583)
at process (jquery.js:3651)
我的webpack配置;
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
frontend: './assets/js/frontend/frontend.js',
backend: './assets/js/backend/backend.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './public/dist'),
publicPath: '/dist/'
},
module: {
rules: [
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
//{ test: /\.css$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }) },
{ test: /\.(jpe?g|gif|png|eot|svg|woff|woff2|ttf)$/, use: 'file-loader' }, // font & image loader
{ test: require.resolve('jquery'), use: [{ loader: 'expose-loader', options: '$' }] }, // globally expose $ for jQuery.
//{ test: /\.js$/, exclude: [/node_modules/], use: [{ loader: 'babel-loader', options: { presets: ['es2015'] } }] }
],
},
resolve: {
modules: [
'node_modules',
'assets/vendor/components'
],
//alias: { jquery: 'jquery/src/jquery.js' }
},
plugins: [
// new ExtractTextPlugin('[name].css'),
new webpack.IgnorePlugin(/\.\/locale$/), // Fixes warning in moment-with-locales.min.js; Module not found: Error: Can't resolve './locale' in ...
new webpack.ProvidePlugin({ $: 'jquery', jquery: 'jquery', jQuery: 'jquery' })
],
devtool: 'source-map'
};
答案 0 :(得分:0)
您需要导入而不是需要
从&#39; jquery&#39;
导入jquery
作为jquery npm包。