使用外部的问题

unr*_*ver 4 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' },
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

Mic*_*ngo 6

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

output: {
    path: path.resolve(__dirname, './build'),
    filename: 'index.js',
    libraryTarget: 'commonjs'
},
Run Code Online (Sandbox Code Playgroud)

webpack / lib / WebpackOptionsApply.js