Javascript 如何在ES6中使用“继承”;“网页包模块绑定器”;?

Javascript 如何在ES6中使用“继承”;“网页包模块绑定器”;?,javascript,ecmascript-6,webpack,es6-module-loader,Javascript,Ecmascript 6,Webpack,Es6 Module Loader,使用babel的webpack模块绑定器导入两个文件时,无法在ES6类中实现继承 我的目录结构看起来像 module.exports = { entry: "./entry.js", output: { path: __dirname, filename: "bundle.js" }, module: { loaders: [ { loader: "babel-loader", // Only run `.js` and `

使用babel的webpack模块绑定器导入两个文件时,无法在ES6类中实现继承

我的目录结构看起来像

module.exports = {
  entry: "./entry.js",
  output: {
    path: __dirname,
    filename: "bundle.js"
  },
  module: {
    loaders: [
    {
      loader: "babel-loader",
      // Only run `.js` and `.jsx` files through Babel
      test: /\.jsx?$/,
      // Options to configure babel with
      query: {
        presets: ['es2015'],
      }
    },
  ]
  }
};
import './content.js';
import './content1.js';
export class addition {
  constructor(){
    this.x = 10 ;
  }
}
class subtraction extends addition{
  constructor(){
    super();
    this.y = this.x - 5 ;
  }
}

var inst = new subtraction();
console.log(inst.x, inst.y)

webpack.config.js看起来像

module.exports = {
  entry: "./entry.js",
  output: {
    path: __dirname,
    filename: "bundle.js"
  },
  module: {
    loaders: [
    {
      loader: "babel-loader",
      // Only run `.js` and `.jsx` files through Babel
      test: /\.jsx?$/,
      // Options to configure babel with
      query: {
        presets: ['es2015'],
      }
    },
  ]
  }
};
import './content.js';
import './content1.js';
export class addition {
  constructor(){
    this.x = 10 ;
  }
}
class subtraction extends addition{
  constructor(){
    super();
    this.y = this.x - 5 ;
  }
}

var inst = new subtraction();
console.log(inst.x, inst.y)
Entry.js看起来像

module.exports = {
  entry: "./entry.js",
  output: {
    path: __dirname,
    filename: "bundle.js"
  },
  module: {
    loaders: [
    {
      loader: "babel-loader",
      // Only run `.js` and `.jsx` files through Babel
      test: /\.jsx?$/,
      // Options to configure babel with
      query: {
        presets: ['es2015'],
      }
    },
  ]
  }
};
import './content.js';
import './content1.js';
export class addition {
  constructor(){
    this.x = 10 ;
  }
}
class subtraction extends addition{
  constructor(){
    super();
    this.y = this.x - 5 ;
  }
}

var inst = new subtraction();
console.log(inst.x, inst.y)
content.js看起来像

module.exports = {
  entry: "./entry.js",
  output: {
    path: __dirname,
    filename: "bundle.js"
  },
  module: {
    loaders: [
    {
      loader: "babel-loader",
      // Only run `.js` and `.jsx` files through Babel
      test: /\.jsx?$/,
      // Options to configure babel with
      query: {
        presets: ['es2015'],
      }
    },
  ]
  }
};
import './content.js';
import './content1.js';
export class addition {
  constructor(){
    this.x = 10 ;
  }
}
class subtraction extends addition{
  constructor(){
    super();
    this.y = this.x - 5 ;
  }
}

var inst = new subtraction();
console.log(inst.x, inst.y)
content1.js看起来像

module.exports = {
  entry: "./entry.js",
  output: {
    path: __dirname,
    filename: "bundle.js"
  },
  module: {
    loaders: [
    {
      loader: "babel-loader",
      // Only run `.js` and `.jsx` files through Babel
      test: /\.jsx?$/,
      // Options to configure babel with
      query: {
        presets: ['es2015'],
      }
    },
  ]
  }
};
import './content.js';
import './content1.js';
export class addition {
  constructor(){
    this.x = 10 ;
  }
}
class subtraction extends addition{
  constructor(){
    super();
    this.y = this.x - 5 ;
  }
}

var inst = new subtraction();
console.log(inst.x, inst.y)
使用webpack生成bundle.js并运行index.html后:出现如下错误


请帮助我了解如何使用webpack module bundler在ES6中实现继承。

每个模块必须导入其所有依赖项:

import {addition} from './content';

class subtraction extends addition {
  // ...
}