๐Ÿš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more โ†’
Socket
DemoInstallSign in
Socket

vue-sfc-library

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-sfc-library

Vue.js SFC build example

1.0.3
latest
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
ย 
Created
Source

vue-sfc-library

Packaging Vue.js components for npm

Project structure

package.json
build/
   rollup.config.js
src/
   wrapper.js
   my-component.vue
dist/

package.json

{
  "name": "my-component",
  "version": "1.2.3",
  "main": "dist/my-component.umd.js",
  "module": "dist/my-component.esm.js",
  "unpkg": "dist/my-component.min.js",
  "browser": {
    "./sfc": "src/my-component.vue"
  },
  "scripts": {
    // !! Build path์™€ ์œ„์˜ main, module, unpkg์˜ ๊ฒฝ๋กœ๊ฐ€ ๊ฐ™์•„์•ผํ•จ !!
    "build": "npm run build:umd & npm run build:es & npm run build:unpkg",
    "build:umd": "rollup --config build/rollup.config.js --format umd --file dist/my-component.umd.js",
    "build:es": "rollup --config build/rollup.config.js --format es --file dist/my-component.esm.js",
    "build:unpkg": "rollup --config build/rollup.config.js --format iife --file dist/my-component.min.js"
  },
  "devDependencies": {
    "node-sass": "^4.12.0",
    "rollup": "^1.15.6",
    "rollup-plugin-buble": "^0.19.6",
    "rollup-plugin-commonjs": "^10.0.0",
    "rollup-plugin-vue": "^5.0.0",
    "sass-loader": "^7.1.0",
    "vue": "^2.6.10",
    "vue-template-compiler": "^2.6.10",
    ...
  },
  ...
}

wrapper.js

ํ•„์š”ํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋นŒ๋“œํ•˜๊ธฐ ์œ„ํ•ด wrapper.js๋ฅผ ํ†ตํ•ด ๋ฌถ์–ด์คŒ (ํ˜น์€ ํ•„์š” ๋กœ์ง ๊ตฌํ˜„)

// Vue ์ปดํฌ๋„ŒํŠธ import
import Component1 from './a.vue'
import Component2 from './b.vue'
import Component2 from './c.vue'

const components = {
  Component1,
  Component2,
  Component3
}

// Vue.use()์—์„œ ์‹คํ–‰๋  ํ•จ์ˆ˜ ์„ ์–ธ
export function install(Vue) {
	if (install.installed) return
  install.installed = true

  Object.keys(components).forEach(name => {
    Vue.component(name, components[name])
  })
}

// Vue.use()๋ฅผ ์œ„ํ•ด ๋ชจ๋“ˆ ์ •์˜ ์ƒ์„ฑ
const plugin = {
	install
}

// ๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์—์„œ Vue๊ฐ€ ์žˆ๋‹ค๋ฉด Auto-install ์ง„ํ–‰
let GlobalVue = null
if (typeof window !== 'undefined') {
	GlobalVue = window.Vue
} else if (typeof global !== 'undefined') {
	GlobalVue = global.Vue
}
if (GlobalVue) {
	GlobalVue.use(plugin)
}

// ๋ชจ๋“ˆ๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์„ ํ—ˆ์šฉ
export components

rollup.config.js

import commonjs from 'rollup-plugin-commonjs' // commonjs
import vue from 'rollup-plugin-vue' // SFC ์ œ์–ด
import buble from 'rollup-plugin-buble' // ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์œ„ํ•ด ํŠธ๋žœ์ŠคํŒŒ์ผ, ํด๋ฆฌํ•„ ์ ์šฉ

export default {
  input: 'src/wrapper.js', // entry
  output: {
    name: 'Vest', // ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ช…
    exports: 'named'
  },
  plugins: [
    commonjs(),
    vue({
      css: true, // style ํƒœ๊ทธ์˜ ์Šคํƒ€์ผ์„ js ํŒŒ์ผ์— ์ฃผ์ž… (inline)
      compileTemplate: true // ํ…œํ”Œ๋ฆฟ์„ render ํ•จ์ˆ˜๋กœ ๋ณ€ํ™˜
    }),
    buble() // ES5๋กœ ํŠธ๋žœ์ŠคํŒŒ์ผ
  ]
}

Build

npm run build

Keywords

vue

FAQs

Package last updated on 19 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts