question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build Vue Components as standalone components

See original GitHub issue

Version

3.0.0-beta.6

Reproduction link

https://codesandbox.io/s/k2qojnor8o

Steps to reproduce

I am using Vue cli and I have a components directory structure like this

- components
  - button
    - button.scss
    - button.vue
    - index.js
  index.js // imports all components

What is expected?

I want to get my build files like this

- build
  - button.js
  - button.css
  - index.js
  - components.css

What is actually happening?

It bundles the entire components into one component I use vue-cli-service build --target lib and after that, I get

- build
  - app.2fa32eb.css
  - app.fa24cd4.js

Is it possible to do this with Vue cli, or do I have to use a custom build.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:21
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
divyamrastogicommented, Apr 12, 2018

@kayandrae07 : Could you maybe share a GitHub repository for the workaround you’ve come up with? It would be really helpful for people who might end up referencing this issue even later. Also, this could become a really cool medium article.

8reactions
kayandracommented, Apr 12, 2018

@renoirb I’m using the solution you provided above, but I’m building the combination of all the components first. Then you can build the individual components.

Another thing I noticed is that you have to add the / after the folder name in the dest option like this:

yarn build --target lib --name Complete2 --dest dist/complete2/

For the main time, this is what I have working

yarn build --target lib --name components components/main.js

yarn build --target lib --name component1 --dest dist/component1 components/component1.js

I also set dist as main in package.json. So in my application I can require like this

import { Component1 } from 'components'
// or
import Component1 from 'components/component1/component1.common'

The second import format is a bit stressful, so I wrote a little script that runs after building the components. The script iterates the directories and renames any file ending with .common.js into index.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create Reusable Blocks of Code with Vue Single-File ...
In this tutorial, you created single-file components and used props and slots to create reusable blocks of code. In the project, you created...
Read more >
Single-File Components - Vue.js
Vue Single-File Components (a.k.a. *.vue files, abbreviated as SFC) is a special file format that allows us to encapsulate the template, logic, ...
Read more >
Is it possible to build a Standalone Vue app? - Stack Overflow
So, it was actually simpler than I thought: I just created a separate entry file for webpack to consume like my-custom-component-entry.js.
Read more >
Building a Vue 3 component library - LogRocket Blog
Creating components in Vue ... A component library will, of course, need some components. Let's create an src folder and add the following...
Read more >
How to create, publish and use your own VueJS Component ...
Step 1 — Setting up the library build · Step 2 — Pointing towards your output file in package. · Step 3 —...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found