Webpack:无法访问另一个文件中定义的js函数

时间:2018-11-24 00:40:32

标签: javascript webpack

我有一个如下所示的weppack配置。

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        polyfill: 'babel-polyfill',
        app: [
            './src/test.js',
            './src/index.js'
        ],
        'function-file': './function-file/function-file.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: 'babel-loader'
            },
            {
                test: /\.html$/,
                exclude: /node_modules/,
                use: 'html-loader'
            },
            {
                test: /\.(png|jpg|jpeg|gif)$/,
                use: 'file-loader'
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html',
            chunks: ['polyfill', 'app']
        }),
        new HtmlWebpackPlugin({
            template: './function-file/function-file.html',
            filename: 'function-file/function-file.html',
            chunks: ['function-file']
        })
    ]
};

我无法调用以test.js形式index.js定义的函数,但是来自test.js的$('document').ready(function() {});正在执行。

任何帮助将不胜感激。

0 个答案:

没有答案