I can't use ES6 in webpack config file

后端 未结 2 598
小鲜肉
小鲜肉 2021-01-19 17:44

Is possible to use ES6 (especially import - instead of require) in webpack config file?

I have e.g.

import webpack from \'webpack\';
<
2条回答
  •  别那么骄傲
    2021-01-19 18:21

    Rabet,

    Do you have a link to a repo of your code? Could be very helpful for debugging if you could link us. It sounds like you may be missing the babel-loader package.

    I've written a tutorial on getting webpack configured in ES6 (for react).

    Below is some of the snippets that may be relevant to you.

    import path from 'path'
    export default {
      entry:['./js/app.js',
      ],
    
      output: {
        filename: 'bundle.js',
        path: path.join(__dirname, 'build'),
        publicPath: 'http://localhost:8080/',
      },
    
      module: {
        loaders: [{
          test: /\.js$/,
          exclude: /node_modules/,
          loaders: ['react-hot', 'babel'],
        }],
      },
    
    }
    

    and my package.json file

    {
     “name”: “Todo_tutorial”,
     “version”: “1.0.0”,
     “description”: “”,
     “main”: “index.js”,
     “scripts”: {
     “test”: “echo \”Error: no test specified\” && exit 1",
     “build”: “webpack --colors --progress”,
     “start”: “webpack-dev-server --hot --inline --color --progress ”
     },
     “author”: “”,
     “license”: “ISC”,
     “dependencies”: {
     “react”: “^0.14.0”
     },
     “devDependencies”: {
     “babel-core”: “^5.8.25”,
     “babel-loader”: “^5.3.2”,
     “flux”: “^2.1.1”,
     “webpack”: “^1.12.2”,
     “webpack-dev-server”: “^1.12.0”
     }
    }
    

    Source: https://medium.com/@ColeMurray/react-flux-in-es6-pt-1-2-e2a7b4aa074e

提交回复
热议问题