2017-04-14 57 views
1

我移動我的項目,jQuery.initializejQuery.initialize與webpack2

require('jquery'); 
require('jquery.initialize/jquery.initialize.min.js'); 

$(document).ready(function() { 
    // ======================================== 
    // comment editor. 
    // ======================================== 
    $('.comment-editor textarea[name=content]').initialize(function() { 
    $(this).froalaEditor({ 

所以這froalaEditor調用不是發生在webpack2和有問題。有任何想法嗎?

也試過這種

$.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) 

my webpack config;

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

你需要做的進口沒有要求

進口jquery從 'jQuery的'

在jQuery NPM包。