我正在与webpack一起运行gulp来解析bootstrap 4中的modal.js文件,但是,我收到以下错误:
> gulp scripts
...
ERROR in ./wp-content/themes/rehub-blankchild/js/modules/Modal.js
Module build failed: SyntaxError: C:\Users\admin\Desktop\project\wp-content\themes\rehub-blankchild\js\modules\Modal.js: This experimental syntax requires enabling the parser plugin: 'objectRestSpread' (223:8)
221 | _getConfig(config) {
222 | config = {
> 223 | ...Default,
| ^
224 | ...config
225 | }
226 | Util.typeCheckConfig(NAME, config, DefaultType)
at Parser.raise (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:830:15)
at Parser.expectPlugin (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2215:18)
at Parser.parseObj (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:3677:14)
at Parser.parseExprAtom (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:3308:21)
at Parser.parseExprSubscripts (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2970:21)
at Parser.parseMaybeUnary (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2948:21)
at Parser.parseExprOps (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2853:21)
at Parser.parseMaybeConditional (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2823:21)
at Parser.parseMaybeAssign (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2779:21)
at Parser.parseMaybeAssign (C:\Users\admin\Desktop\project\node_modules\babylon\lib\index.js:2809:27)
@ ./wp-content/themes/rehub-blankchild/js/scripts.js 7:36-62
[15:32:06] Finished 'scripts' after 1.86 s
我的webpack配置如下所示:
const path = require('path'),
settings = require('./settings');
module.exports = {
entry: {
App: settings.themeLocation + "js/scripts.js"
},
output: {
path: path.resolve(__dirname, settings.themeLocation + "js"),
filename: "scripts-bundled.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
}
}
}
]
}
}
我的gulp任务gulp scripts
基本上启动了webpack:
gulp.task('scripts', function(callback) {
webpack(require('./webpack.config.js'), function(err, stats) {
if (err) {
console.log(err.toString());
}
console.log(stats.toString());
callback();
});
});
我为babel安装了plugin-syntax-object-rest-spread
。请参阅下面的package.json以了解我的依赖项:
" devDependencies":{ " @ babel / core":" 7.0.0-beta.34", " @ babel / plugin-syntax-object-rest-spread":" ^ 7.0.0-beta.44", " @ babel / preset-env":" 7.0.0-beta.34", " autoprefixer":" 7.2.2", " babel-loader":" 8.0.0-beta.0", "浏览器同步":" 2.18.13", " gulp":" 3.9.1", " gulp-postcss":" 7.0.0", " postcss-color-function":" 4.0.1", " postcss-hexrgba":" 1.0.0", " postcss-import":" 11.0.0", " postcss-mixins":" 6.2.0", " postcss-nested":" 3.0.0", " postcss-simple-vars":" 4.1.0", " webpack":" 3.10.0" }, "依赖":{ " jquery":" 3.2.1", " normalize.css":" 7.0.0", " slick-carousel":" 1.8.1" }
有什么建议我做错了以及为什么会出现上述错误?
感谢您的回复!
答案 0 :(得分:0)
通过修改webpack修复错误。请参阅以下如何修改规则部分:
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [require('@babel/plugin-proposal-object-rest-spread')]
}
}
}
]