mkdist icon indicating copy to clipboard operation
mkdist copied to clipboard

[DOC] How to use?

Open xialvjun opened this issue 3 years ago • 3 comments

I have a directory:

project
└── src
    └── map.vue

map.vue:

<template>
  <div @click="onClick">{{count}}</div>
</template>

<script lang="ts">
export default {
  data() {
    return { count: 0 };
  },
  method: {
    onClick() {
      this.count += 1;
    }
  }
}
</script>

<style lang="less" scoped>
div {
  color: red;
}
</style>

Then:

cd project
mkdist --format=esm --ext=vue -d

Then it get:

project
├── dist
│   └── map.vue
└── src
    └── map.vue

What I really want to get is:

project
├── dist
│   └── map.js
└── src
    └── map.vue

xialvjun avatar Jun 15 '21 03:06 xialvjun

Hi @xialvjun. Actually, it is on purpose how it works with mkdist. By splitting/bundling .vue files, you probably also need extra .css chunks (*). mkdist preserves same .vue format but transforms <script> part for dist/map.vue so you can use typescript inside it. <style> tag with less is not supported yet so enduser needs to have less-loader installed if using lang="less"

(*) In traditional bundling methods, extracting CSS makes users always importing it from npm package regardless component used in page or not and by inlining in js, it adds extra overhead for runtime injection code.

pi0 avatar Jun 15 '21 08:06 pi0

I don't understand. If I still got a .vue file, how can I publish my vue component to npm without forcing the user config vue-cli to include node_modules/my_package.

xialvjun avatar Jun 15 '21 09:06 xialvjun

By directly publishing dist/*.vue files to npm package. Users can simply point to my_package/dist/component.vue (or you can have an index.mjs exporting them by name)

Both vue-cli (src) and nuxt (src) (and any standard vue configuration) already transpile .vue files from node_modules.

pi0 avatar Jun 15 '21 10:06 pi0

Is it possible to transpile from UMD or CJS to ESM with the tool? It is currently not clear, but it should be a killer feature if it is the case and mentioned in the documentation :)

I suppose as the [--format=cjs|esm] [--ext=mjs|js|ts] mention the CJS format. Anyway I will check it later.

Lyokolux avatar Oct 20 '22 07:10 Lyokolux

@Lyokolux Feel free to open a new question if still is the case.

pi0 avatar Jul 18 '23 15:07 pi0