webpack + babel npm不想开始

时间:2017-12-26 21:59:03

标签: javascript node.js npm webpack babel

超级善意的人!!我只是这个神奇的魔术工艺的初学者,比如编程:)我有这种 问题。基本上我知道所以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$ 

`

请帮助!!

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

逗号位置错误,您应该将,'./scss/main.scss'上面的一行移到'./js/nav.js'