Webpack 为什么我需要';默认值';模块内导出?

Webpack 为什么我需要';默认值';模块内导出?,webpack,module,Webpack,Module,我正在导出一些带有ES6语法的模块,并将它们与webpack捆绑在一起。 但这仅在我包含default关键字时有效。这有什么用 为什么我不能只使用导出类人员?Webpack抱怨它需要默认类 export class Person // doesn't work export default class { // works constructor (id) { this.name = id } logname () { c

我正在导出一些带有ES6语法的模块,并将它们与webpack捆绑在一起。 但这仅在我包含
default
关键字时有效。这有什么用

为什么我不能只使用导出类人员?Webpack抱怨它需要
默认类

export class Person       // doesn't work
export default class {    // works
    constructor (id) {
        this.name = id
    }
    logname () {
        console.log("Person: " + this.name)
    }
}
应用程序

如果你正在使用这个

export class Example
那么您的导入应该如下所示

import { Example } from 'your-file';
// example.js
export default class Example

// your-another-file
import MyClass from 'example';
如果要重命名类(示例->MyClass),需要

import { Example as MyClass } from 'your-file'
但是如果您使用的是默认值,那么您的代码将如下所示

import { Example } from 'your-file';
// example.js
export default class Example

// your-another-file
import MyClass from 'example';

有时我们需要命名导出,默认不是一个好的解决方案

谢谢!我完全错过了那些
{…}