javascript - webpack+babel npm 不想启动

标签 javascript node.js npm webpack babeljs

super 有善意的人!我只是这个神奇的魔法工艺的初学者,比如编程:)而且我有这样的能力 问题。基本上我知道 web pack 告诉我出了什么问题,但是 不过,我可以修复它:( 这是我的 webpack.config.js :

const path = require('path') 
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

module.exports = {
entry: [
'babel-polyfill',  
'./js/index.js',
'./js/nav.js'
'./scss/main.scss',
],
output: {
filename: 'index.js', 
libraryTarget: 'commonjs',
path: path.resolve('./dist/'),
},
module: {
rules: [
  {
    test: /\.css$/,
    loader: ExtractTextPlugin.extract(['css-loader']),
  },
  {
    test: /\.(sass|scss)$/,
    loader: ExtractTextPlugin.extract(['css-loader', 'sass-
 loader','babel-loader']),
  },
  {
    test: /\.(png|jpg|gif|svg)$/,
    use: [
      {
        loader: 'url-loader',
        options: {
          limit: 8192
        }
      }
    ]
  },
    {
  test: /\.js$/,
  exclude: /(node_modules|bower_components)/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env']
    }
  }
 },


  ]
 },
 plugins: [
 new webpack.optimize.UglifyJsPlugin({
  output: {
    comments: false
  }
 }),
  new ExtractTextPlugin({
  filename: 'styles.css',
  allChunks: true,
}),
]
}

my package.json :

{
"name": "simple-webpack-boilerplate",
"version": "0.0.1",
"scripts": {
"start": "webpack --config webpack.config.js --watch",
"build": "webpack --config webpack.config.js"
},
"babel": {
"presets": [
  "es2015"
 ]
 },
 "author": "Michał Grabowski (michal.grabowski@gmail.com)",
 "license": "MIT",
"description": "",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^8.0.0-beta.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"browser-sync": "^2.18.13",
"css-loader": "0.28.7",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "^1.1.5",
"node-sass": "4.7.2",
"resolve-url-loader": "^2.2.1",
"sass-loader": "6.0.6",
"url-loader": "^0.6.2",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},
"dependencies": {
"@babel/core": "^7.0.0-beta.35",
"@babel/preset-env": "^7.0.0-beta.35",
"init": "^0.1.2"
}
 }

最后,当我尝试启动 npm 时,我在终端上出现的错误 :

`> simple-webpack-boilerplate@0.0.1 start 
/Users/Niemiec/Desktop/michal_web
> webpack --config webpack.config.js --watch

/Users/Niemiec/Desktop/michal_web/webpack.config.js:10
'./scss/main.scss',
^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at requireConfig   
npm ERR! Failed at the simple-webpack-boilerplate@0.0.1 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!     /Users/Niemiec/.npm/_logs/2017-12-26T21_30_23_846Z-
debug.log
Krzysztofs-MacBook-Pro:michal_web Niemiec$ 

`

请帮忙!!

最佳答案

您的 entry 列表中似乎缺少 ,。尝试一下:

entry: [
    'babel-polyfill',  
    './js/index.js',
    './js/nav.js'
    './scss/main.scss',
],

关于javascript - webpack+babel npm 不想启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47984120/

相关文章:

javascript - 使用扩展运算符设置键名

javascript - 在 PHP 中附加字符串的问题

node.js - 使用 Sails.js 进行全文搜索

javascript - PATH npm 中的空格

css - 有没有办法将我的样式用作 react 中的外部 css 文件?

node.js - npm 和 node 版本不兼容会产生错误

javascript - 使用 D3.js 从元素获取宽度

javascript - 默认添加 babel-polyfill 吗?

node.js - 使用 Node.js 作为 Shell

Node.js 多行输入