npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-ts-vue

v0.5.0

Published

Vue bundler with Typescript and Rollup

Downloads

39

Readme

Rollup-Plugin-Ts-Vue

Plugin for Rollup to bundle Vue components written in TypeScript.

This plugin was in inspired by rollup-plugin-typescript, which uses Typescript's API. Added support for SCSS and Vue.

Feel free to use my full boilerplate project here on Github.

Why

Why another plugin?? I love writing in Typescript and love the Vue single component concept. However, the similar plugins rely on other tools to complete the job. Wanted a way to reduce over-head of other tool-sets like; Babel, Webpack, etc. and replace with a simpler tool.

NOTE: currently scoped styles are partially supported and in-beta. Work-in-Progess

Rollup Config

import resolve from "./node_modules/@rollup/plugin-node-resolve/dist/index.es";
import vue from "./node_modules/rollup-plugin-ts-vue/dist/rollup-plugin-ts-vue.es";

export default {
    input: "./src/main.ts",
    output: {
        name: "app",
        format: "iife",
        file: "./dist/js/app.js",
        globals: {
            "vue": "Vue",
            "vue-router": "VueRouter",
            "vuex": "Vuex",
            "vue-property-decorator": "VueClassComponent",
            "vue-class-component": "VueClassComponent"
            "axios": "axios"
        },
        sourcemap: true,
        sourcemapFile: "./dist/js/app.js.map"
    },
    plugins: [
        resolve(),
        // null == defaults to tsconfig.json
        vue(null, {
            output: "./dist/css/site.css",
            includePaths: ["src/scss"]
        })
    ],
    external: [
        "vue", 
        "vue-router", 
        "vuex", 
        "vue-class-component",
        "axios"
    ]
}

Examples of Strong-Typed Vue Components

Standard Vue Mixin Object

<template>
    <div>{{msg}}</div>
</template>

<script lang="ts">
import Vue, { ComponentOptions } from "vue";

export default {
    data() {
        return {
            msg: "Hello World"
        }
    }
} as ComponentOptions<any>
</script>

<style lang="scss">
</style>

Vue Extend

<template>
    <div>{{msg}}</div>
</template>

<script lang="ts">
import Vue from "vue";

export default Vue.extend({
    data() {
        return {
            msg: "Hello World"
        }
    },
    created() {
        let vm = this as VueComp;
        vm.msg = "Hello World Too!!";
    }
});

interface VueComp extends Vue {
    msg: string;
}
</script>

<style lang="scss">
$myColor = blue;

div {
    color: $myColor;
}
</style>

vue-property-decorator

<template>
    <div>{{msg}}</div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

@Component({
    name: "component-template"
})
export default class ComponentTemplate extends Vue {    
    msg: string = "Hello World";

    created() {
        this.msg = "Hello World Too!!";
        console.log(Created: life-cycle hook);
    }
}
</script>

<style lang="scss">
div {
    color: blue;
    
    a {
        color: green;
    }
}
</style>

Typescript Path Translation

When using paths in tsconfig, rollup doesn't understand how to translate so it may resolve the module. When using something like this; import MyMod from "@/components/my-module". Rollup will assuming its an external dependencies. This plugin will attempt to resolve and correct the module path before passing to Rollup.

tsconfig.json

{
    ...

    "baseUrl": ".",
    "paths": {
      "@/*": [ "src/*" ]
    }

    ...
}

Change Log

  • 0.1.0 inital release
  • 0.2.0 fix nested template tags being removed.
  • 0.3.0 scoped CSS (beta) and Typescript Path Translation.
  • 0.4.0 include sass compiler into project vs using another plugin. Also switch from node-sass to sass due to [email protected] errors.
  • 0.5.0 While working with CI/CD in Azure, Rollup failed to create the missing directory from the plugin's CSS output path:
    • vue(null, { output: "./dist/css/site.css", includePaths: ["src/scss"] })