我正在尝试按照文档编写一个 cloudflare 工作者,并使用 Webpack 生成一个要上传的文件。
在文档中运行脚本后:
curl -X PUT "https://api.cloudflare.com/client/v4/zones/ZONE_ID/workers/script" -H "Content-Type:application/javascript" -H "X-Auth-Email:CLOUDFLARE_EMAIL" -H "X-Auth-Key:CLOUDFLARE_KEY" --data-binary "@dist/index.js"
我收到以下错误:
{
"result": null,
"success": false,
"errors": [
{
"code": 10021,
"message": "Uncaught ReferenceError: exports is not defined\n at line 1\n"
}
],
"messages": []
}
我的 webpack 配置:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: ['./src/index.js'],
target: 'web',
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
}],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'dist'),
filename: 'index.js',
},
};
我找不到有关使用 webpack 创建工作人员的文档或示例,但我认为这不是新事物 :)
谢谢