Код основного файла
./src/index.js
:
let a = { s: 4 }
let b = { ...a };
console.log(b);
Вот файл webpack.config.js:
const path = require("path");
module.exports = {
entry: "./src/index.js",
output: {
path: path.join(__dirname, "dist"),
filename: "bundle.js"
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader"
}]
}
}
Вот package.json:
{
"name": "webpackreacttest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.5.2",
"babel-preset-es2015": "^6.24.1",
"webpack": "^2.6.1"
}
}
ну и .babelrc:
{
"presets": ["es2015"]
}
если попробовать собрать этот проект webpack через>>
npm start
, то происходит ошибка:
D:\projects\nodejs\webpackreacttest>npm start
> webpackreacttest@1.0.0 start D:\projects\nodejs\webpackreacttest
> webpack
Hash: ea52a0a36c328ecb7082
Version: webpack 2.6.1
Time: 612ms
Asset Size Chunks Chunk Names
bundle.js 3.19 kB 0 [emitted] main
[0] ./src/index.js 558 bytes {0} [built] [failed] [1 error]
ERROR in ./src/index.js
Module build failed: SyntaxError: D:/projects/nodejs/webpackreacttest/src/index.js: Unexpected token (2:10)
1 | let a = { s: 4 }
> 2 | let b = { ...a };
| ^
3 | console.log(b);
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! webpackreacttest@1.0.0 start: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the webpackreacttest@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\toly1\AppData\Roaming\npm-cache\_logs\2017-06-14T17_53_46_285Z-debug.log