E(...).foundation不是功能的基础上6.4的WebPack

问题描述 投票:0回答:1

我是新来基金会6.4。我有一个错误,当我使用的$(document).foundation();

这是下面的代码:

1.webpack.config.js

const webpack = require('webpack');

module.exports = {
    entry: ['./src/index',
    'script-loader!jquery/dist/jquery.min.js',
    'script-loader!foundation-sites/dist/js/foundation.min.js'],
    mode: "production",
    output: {
        path: __dirname,
        filename: './public/bundle.js'
    },
    performance: {
        hints: false
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        })
    ],
    module: {
        rules: [
            {
                test: /\.jsx$|\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ['react','es2015'],
                    }
                }
            },
        ]
    }
};
  1. index.index

import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import {createStore,compose} from 'redux';
import reducer from './app/reducers/reducerCombine';
import MainContainer from "./app/container/MainContainer";

require('style-loader!css-loader!foundation-sites/dist/css/foundation.min.css');
$(document).ready(()=>$(document).foundation());

const store= createStore(reducer,compose(window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()));

ReactDOM.render(
    <Provider store={store}>
        <MainContainer/>
    </Provider>, document.getElementById('root'));

当我运行这个程序,我在控制台得到一个错误:遗漏的类型错误:E(...)的基础是不是一个函数。

任何人都可以帮助我^^。预先感谢 :)

javascript reactjs webpack zurb-foundation zurb-foundation-6
1个回答
1
投票

尝试导入jQuery和它添加到窗口:

import { Foundation } from 'foundation-sites';
import jquery from 'jquery';

window.jQuery = jquery;
window.$ = jquery;

Foundation.addToJquery($);

jQuery(document).ready($ => ($(document).foundation()));
© www.soinside.com 2019 - 2024. All rights reserved.