我试图使用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' },
]
}
}
答案 0 :(得分:5)
您需要将output.libraryTarget
设置为commonjs
。 Webpack使用libraryTarget
来确定用于外部的导入类型。将您的output
更改为:
output: {
path: path.resolve(__dirname, './build'),
filename: 'index.js',
libraryTarget: 'commonjs'
},