e(...).foundation 不是带有 Webpack 的 Foundation 6.4 函数

e(...).foundation is not a function Foundation 6.4 with Webpack

我是 Foundation 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'));

当我 运行 这个应用程序时,我在控制台中收到一个错误:Uncaught TypeError: e(...).foundation is not a function.

任何人都可以帮助我^^。提前致谢:)

尝试导入 jQuery 并将其添加到 window:

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

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

Foundation.addToJquery($);

jQuery(document).ready($ => ($(document).foundation()));