简体   繁体   English

使用vue-cli-service建库,怎么转译?

[英]Use vue-cli-service to build a library, how to transpile?

I'm trying to build a library (mostly some.vue components) to reuse in different projects (no public npm) with vue-cli-service.我正在尝试使用 vue-cli-service 构建一个库(主要是 some.vue 组件)以在不同的项目(没有公共 npm)中重用。 Apparently everything its already setup, and I can confirm that the build is fine (js, and css).显然一切都已经设置好了,我可以确认构建是好的(js 和 css)。 However, I'm unable to use it in a separate project as an external module because it uses the spread operator (and probably more ES20XX features no yet parsed).但是,我无法在单独的项目中将它用作外部模块,因为它使用扩展运算符(可能还有更多尚未解析的 ES20XX 功能)。

Module parse failed: Unexpected token (2683:8)
You may need an appropriate loader to handle this file type.
|     params() {
|       const queryParams = {
|         ...this.filters,
|         ...this.sorting,
|         ...this.config.params,

This is the standard command I'm using to build the library这是我用来构建库的标准命令

vue-cli-service build --target lib --name [mylibname]./src/components/index.js

By default the bundle should be already polyfilled but it seems to me that it's not the case.默认情况下,捆绑包应该已经填充了,但在我看来并非如此。

I've read that I might change the webpack configuration on the project I'm using into, but I'm against parsing the whole node_module folder and also I would love to just have the simplest workflow possible (like import a module and its css).我已经读到我可能会更改我正在使用的项目的 webpack 配置,但我反对解析整个node_module文件夹,而且我希望拥有最简单的工作流程(比如导入模块及其 css )。

So my question is, how to polyfill my bundle to be perfectly usable in no matter what Vue project without any hassle?所以我的问题是,如何轻松地填充我的包以在任何 Vue 项目中完全可用?

Ok, it seems that reinitializing the project with vue-cli without typescript and with separated configuration files instead of into package.json was a good idea, as now is transpiled as needed.好的,似乎使用 vue-cli 重新初始化项目而不使用 typescript 并使用单独的配置文件而不是 package.json 是一个好主意,因为现在需要进行转换。

var queryParams = _objectSpread({}, this.filters, {}, this.sorting, {}, this.config.params);

Unfortunately the hidden configuration of vue-cli webpack can't help to see what has changed.不幸的是,vue-cli webpack 的隐藏配置不禁让人看看有什么变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM