【发布时间】:2020-01-21 05:19:23
【问题描述】:
我有一个类,我在其中使用一些像这样的静态属性:
class Entity {
static LIMIT = 10;
}
所以,我可以做到:
Entity.LIMIT
为了做到这一点,我使用了 babel plugin-proposal-class-properties,在我的 .babelrc 中我有:
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
我正在使用 jest,我的测试使用该配置通过。现在我需要在vuejs 组件中使用Entity 类的功能。但我得到了错误:
模块解析失败:意外令牌。您可能需要适当的加载程序来处理此文件类型
我还在我的项目根目录中尝试了一个 babel 配置文件:babel.config.js
module.exports = {
presets: ["@babel/preset-env"],
plugins: [
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
};
但是没有用。 如何配置 vuejs,让这个 babel 插件工作?
我正在使用 vue2.6.11 和 vue-cli 3
【问题讨论】:
-
这应该可以通过 Vue-CLI 3 开箱即用。您是否尝试在没有这个特定 babel 插件的情况下这样做?
-
你解决了吗?
-
不,我只是停止研究