使用外部问题

时间:2017-03-20 18:09:39

标签: webpack

我试图使用obj / commonjs语法设置外部但是查看它返回的module.exports = undefined

继承我的配置:

var path = require('path');

module.exports = {
    entry: path.resolve(__dirname, './src/index.js'),
    output: {
        path: path.resolve(__dirname, './build'),
        filename: 'index.js'
    },
    target: 'node',
    resolve: {
        alias: {
            Utilities: path.resolve(__dirname, './src/utilities/')
        },
        extensions: ['.js', '.jsx']
    },
    externals: {
        tessel: {
            commonjs: "tessel",
        },
    },
    module: {
        rules: [
            { test: /\.(js|jsx)$/, use: 'babel-loader' },
        ]
    }
}

1 个答案:

答案 0 :(得分:5)

您需要将output.libraryTarget设置为commonjs。 Webpack使用libraryTarget来确定用于外部的导入类型。将您的output更改为:

output: {
    path: path.resolve(__dirname, './build'),
    filename: 'index.js',
    libraryTarget: 'commonjs'
},

来源webpack/lib/WebpackOptionsApply.js