我正在尝试构建一个Safari扩展程序。由于浏览器中无法使用require
或import
,因此我正在尝试设置Webpack和Babel。我非常依赖于我发现的其他示例,但是没有成功。任何帮助都将不胜感激。
webpack.conf.js
const path = require('path')
module.exports = {
target: 'web',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, "ReduxDevTools.safariextension"),
filename: 'index.js'
},
module: {
rules: [
{
test: /src\/.+\.js$/,
exclude: /(node_modules|ReduxDevTools\.safariextension)/,
use: {
loader: 'babel-loader',
options: {
"presets": [
["@babel/preset-env", {
"targets": {
"safari": 10
}
}],
"@babel/preset-stage-0"
],
"plugins": [
["@babel/plugin-transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "@babel/runtime"
}]
]
}
}
}
]
}
}
package.json
"scripts": {
"build": "./node_modules/.bin/webpack",
"dev": "nodemon --watch ./src --exec yarn run build"
},
目录
├── CertificateSigningRequest.certSigningRequest
├── ReduxDevTools.safariextension
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── logo-2-1024.png
│ │ ├── logo-2-128.png
│ │ ├── logo-2-16.png
│ │ ├── logo-2-256.png
│ │ ├── logo-2-32.png
│ │ ├── logo-2-512.png
│ │ └── logo-2-64.png
│ ├── Info.plist
│ ├── Settings.plist
│ ├── index.html
│ └── index.js
├── dist
├── package.json
├── src
│ └── index.js
├── webpack.config.js
├── yarn-error.log
└── yarn.lock
错误
[nodemon] starting `yarn run build`
warning ../package.json: No license field
$ ./node_modules/.bin/webpack
Hash: e42a920b430f30cdd9f4
Version: webpack 3.10.0
Time: 1637ms
Asset Size Chunks Chunk Names
index.js 4.08 kB 0 [emitted] main
[0] ./src/index.js 1.61 kB {0} [built] [failed] [1 error]
ERROR in ./src/index.js
Module build failed: TypeError: Cannot read property 'helpers' of undefined
at _default (/Users/noah/Projects/ReduxDevtoolsExtension/node_modules/@babel/plugin-transform-runtime/lib/index.js:17:25)
at Function.memoisePluginContainer (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/noah/Projects/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/Users/noah/Projects/ReduxDevtoolsExtension/node_modules/babel-loader/lib/index.js:50:20)
at Object.module.exports (/Users/noah/Projects/ReduxDevtoolsExtension/node_modules/babel-loader/lib/index.js:175:20)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[nodemon] app crashed - waiting for file changes before starting...