From 761ddb0f34b67b14706db9dcd80bc566471d6b7a Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Sat, 5 Nov 2016 15:47:22 +0200 Subject: [PATCH] add build steps for CDN distribution --- README.md | 15 ++++++++++++++- package.json | 15 ++++++++++++--- rollup.config.js | 22 +++++++++++++++------- scripts/update-cdn.js | 32 ++++++++++++++++++++++++++++++++ yarn.lock | 4 ++-- 5 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 scripts/update-cdn.js diff --git a/README.md b/README.md index 662d753..bac5c16 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ - [Installation](#installation) - [Yarn](#yarn) - [NPM](#npm) + - [CDN](#cdn) - [Usage](#usage) - [Step 1: Preparing the plugin](#step-1-preparing-the-plugin) - [Step 2: Server Rendering (Optional)](#step-2-server-rendering-optional) @@ -67,7 +68,7 @@ - [`noscript` ([Object])](#noscript-object) - [`changed` (Function)](#changed-function) - [How `metaInfo` is Resolved](#how-metainfo-is-resolved) - - [Lists of Tags](#lists-of-tags) + - [Lists of Tags](#lists-of-tags) - [Performance](#performance) - [How to prevent the update on the initial page render](#how-to-prevent-the-update-on-the-initial-page-render) - [FAQ](#faq) @@ -98,6 +99,18 @@ $ yarn add vue-meta $ npm install vue-meta --save ``` +### CDN + +Use the links below - if you want a previous version, check the instructions at https://unpkg.com. + + +**Uncompressed:** +> https://unpkg.com/vue-meta@0.0.0/lib/vue-meta.js + +**Minified:** +> https://unpkg.com/vue-meta@0.0.0/lib/vue-meta.min.js + + # Usage ## Step 1: Preparing the plugin diff --git a/package.json b/package.json index 6dc1ec1..3e56913 100644 --- a/package.json +++ b/package.json @@ -42,12 +42,15 @@ "rollup-plugin-node-resolve": "^2.0.0", "snazzy": "^5.0.0", "standard": "^8.5.0", + "uglify-js": "^2.7.4", + "update-section": "^0.3.3", "vue": "^2.0.3", "vue-loader": "^9.7.0", "webpack": "beta", "webpack-dev-server": "beta" }, "homepage": "https://github.com/declandewet/vue-meta", + "jsnext:main": "lib/jsnext/vue-meta.js", "keywords": [ "attribute", "google", @@ -63,7 +66,8 @@ "vue" ], "license": "MIT", - "main": "lib", + "main": "lib/vue-meta.js", + "module": "lib/jsnext/vue-meta.js", "nyc": { "exclude": [ "test/**/*.js" @@ -74,14 +78,19 @@ "type": "git" }, "scripts": { - "codecov": "codecov", "build": "rollup -c", + "codecov": "codecov", "dev": "babel-node examples/server.js", "lint": "standard --verbose | snazzy", + "minify": "uglifyjs lib/vue-meta.js -cm --comments -o lib/vue-meta.min.js", + "postbuild": "npm run minify", + "postminify": "npm run toc", + "posttoc": "npm run update-cdn", "prebuild": "rimraf lib", "pretest": "npm run lint", "test": "cross-env NODE_ENV=test karma start karma.conf.js", - "toc": "doctoc README.md --title '# Table of Contents'" + "toc": "doctoc README.md --title '# Table of Contents'", + "update-cdn": "babel-node scripts/update-cdn.js" }, "standard": { "globals": [ diff --git a/rollup.config.js b/rollup.config.js index dfc62be..3e99506 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,17 +3,25 @@ import nodeResolve from 'rollup-plugin-node-resolve' import json from 'rollup-plugin-json' import buble from 'rollup-plugin-buble' +const pkg = require('./package.json') + export default { entry: './src/index.js', - format: 'umd', - dest: './lib/index.js', - moduleName: 'VueMeta', + targets: [ + { dest: pkg.main, format: 'umd', moduleName: 'VueMeta' }, + { dest: pkg['jsnext:main'], format: 'es' } + ], plugins: [ json(), - nodeResolve({ - jsnext: true - }), + nodeResolve({ jsnext: true }), commonjs(), buble() - ] + ], + banner: ` + /** + * vue-meta v${pkg.version} + * (c) ${new Date().getFullYear()} Declan de Wet + * @license MIT + */ + `.replace(/ {4}/gm, '').trim() } diff --git a/scripts/update-cdn.js b/scripts/update-cdn.js new file mode 100644 index 0000000..84184ec --- /dev/null +++ b/scripts/update-cdn.js @@ -0,0 +1,32 @@ +import { readFileSync, writeFileSync } from 'fs' +import updateSection from 'update-section' +import { name, main, version } from '../package.json' + +console.log(`Updating CDN info to latest v${version} release...`) + +const readmePath = './README.md' +const cdnUrl = `https://unpkg.com/${name}@${version}/${main}` +const minifiedUrl = cdnUrl.replace('.js', '.min.js') + +const content = readFileSync(readmePath, 'utf-8') + +const update = ` + + **Uncompressed:** + > ${cdnUrl} + + **Minified:** + > ${minifiedUrl} + +`.trim().replace(/ {2}/gm, '') + +const updated = updateSection( + content, + update, + (line) => (/