Coder Social home page Coder Social logo

vue-sfc-rollup's Introduction

vue-sfc-rollup

vue-sfc-rollup is a utility that scaffolds a minimal setup for compiling a Vue Single File Component (SFC) - or library of multiple SFCs - into a form ready to share via npm.

TL;DR

Install globally

# Install globally (recommended)
npm install -g vue-sfc-rollup
sfc-rollup-init

OR use via npx

# For immediate, no-install usage
npx vue-sfc-rollup

Then...

# fill in prompts
cd path/to/my-component-or-lib
# if single component
vue serve ./src/my-component.vue # Use @vue/cli or other live-refresh coding
# if library
vue serve ./src/lib-dev.vue # Use @vue/cli or other live-refresh coding
# Do dev stuff...
npm run build
# Ready to publish!

Details

The vue-sfc-rollup utility scaffolds 4 files (6 in library mode) for you to kick of your SFC development. These files include a minimal rollup config, a corresponding package.json file with build script and dependencies, a wrapper used by rollup when packaging your SFC, and a sample SFC to kick-start development. In library mode, there is also an 'index' which declares the components exposed as part of your library, and a sample library usage file which can be used to load/test your library during development.

If you wish to integrate this into an existing SFC, please check out the vue-sfc-rollup source. The files generated by this utility are located inside the templates directory of the repository. Merge the important bits of those file with your existing code, and you'll be good to go.

Install

If you just want to try vue-sfc-rollup, you can run it directly via npx vue-sfc-rollup.

For repeated use, however, you really should install it globally. To do so, simply open a terminal and execute the following:

npm install -g vue-sfc-rollup

Now, whenever you want to start a new component, you can just type sfc-rollup-init to run the wizard, and it will scaffold a new SFC for you!

Using the vue-sfc-rollup wizard

Using the vue-sfc-rollup wizard is simple. With vue-sfc-rollup installed globally, enter the following:

sfc-rollup-init
# fill in prompts

The wizard will then prompt you for the following:

  • select mode: Declare whether you want to scaffold a single component or a library of components.
  • npm name: This is how people will find your component/library in npm. Please refer to the official npm docs for details of what to enter here
  • component name (Single Component Mode Only): This is the kebab-case version of your SFC component name - what your component's tag would be if you were to use this in an HTML page or another component. Since any kebab-case tag name would also be a safe file name, this will also be the name of the generated files.
  • save path: Where do you want to save this component? By default, the wizard will use your current directory and create a new folder with the kebab-case name as your component/library (eg. ./my-component-or-library).

After prompting you for this information, the wizard then creates copies of the files found in the templates directory and performs some variable replacement using the information enterd.

Developing your SFC

vue-sfc-rollup is currently focused on packaging your SFC for distribution via npm. The Vue CLI is excellent for the actual development process of your SFC, and it is recommended you use the official tooling. With v3 of the Vue CLI installed globally, you can truly develop your SFC with zero configuration just by entering the following commands:

cd path/to/my-component-or-lib
# if single component
vue serve ./src/my-component.vue
# if library
vue serve ./src/lib-dev.vue

This will start up a webpack dev server with hot reloading and all the other awesomeness!

Packaging your SFC

Once your development is done, it's time to package your component to publish to npm. The actual process of publishing to npm is left up to you, but the whole purpose of this project is to compile your SFC/library so that it's packaged and ready to go.

cd path/to/my-component-or-lib
npm run build
# rollup does its thing...done!

Running the build script results in 3 compiled files in the dist directory, one for each of the main, module, and unpkg properties listed in your package.json file. With these files are generated, you're ready to go!

vue-sfc-rollup's People

Contributors

mgdodge avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.