webpack ,webpack-dev-server打包问题

cats.js:

var cats = ['dave','henry','martha'];
module.exports = cats;

app.js:

cats = require('./cats.js');console.log(cats);

webpack.config.js :

module.exports = {
  entry: './app.js',
  output: {
    path: path.resolve(__dirname,'dist'),
    publicPath: '/assets/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      test: /\.js$/,      include: [
        path.join(__dirname,'src')
      ],      exclude: /node_modules/,
      loader: 'babel-loader',
    }]
  }
};

运行:./node_modules/.bin/webpack-dev-server --inline

运行后webpack-dev-server后打开也页面报错:

bundle.js:7531 Uncaught ReferenceError: cats is not defined

明明都require怎么会没定义呢 刚开始接触webpack,希望各位能够帮帮小弟


潇潇雨雨
浏览 938回答 1
1回答

墨色风雨

cats没声明,改下:var cats = require('./cats.js');console.log(cats);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript