Webpackのスーパークラスを拡張するサブクラスに問題があります。Webpackのインポートモジュールからの継承
私のスーパークラス:コア/ Main.js
class Main {
constructor() {
console.log('Main Class Initialized');
}
}
module.exports = Main;
サブクラス:アプリ/ Launch.js
var Main = require('core/Main.js');
class Launch extends Main {
constructor() {
console.log('Before Super')
super();
console.log('Launch Class Initialized')
}
}
私はアプリ/ Launch.jsの内部console.log(Main)
は、ログに記録し、それを提出した場合Mainと 'Before Super'もログに記録されますが、super()
を呼び出すと、それが壊れてしまいます。理由はわかりません。
How to achieve inheritance in ES6 with “webpack module bundler”?は役に立ちませんでした。 export class Main {}
の場合はmodule.exports
、import {Main} from 'core/Main.js'
の場合はrequire('core/Main.js')
を交換しましたが、動作しませんでした。 webpack 1.14.0を使用しています。
継承はwebpackとは関係ありません。あなたの質問は、実際には "どうやってwebpackを使って正しくモジュールをインポートするのですか?" –