├── .gitattributes ├── generators └── app │ ├── templates │ ├── dist │ │ └── .gitkeep │ ├── _gitignore │ ├── config │ │ ├── prod.env.js │ │ ├── dev.env.js │ │ └── index.js │ ├── demo │ │ ├── assets │ │ │ └── _logo.png │ │ ├── seed │ │ │ ├── .babelrc │ │ │ ├── router │ │ │ │ └── index.js │ │ │ ├── components │ │ │ │ └── Hello.vue │ │ │ ├── index.html │ │ │ └── App.vue │ │ └── _main.js │ ├── _babelrc │ ├── build │ │ ├── seed │ │ │ ├── dev-client.js │ │ │ ├── vue-loader.conf.js │ │ │ ├── build.js │ │ │ ├── webpack.dev.conf.js │ │ │ ├── check-versions.js │ │ │ ├── webpack.base.conf.js │ │ │ ├── utils.js │ │ │ ├── dev-server.js │ │ │ └── webpack.prod.conf.js │ │ └── _build.rollup.js │ ├── _README.md │ ├── src │ │ └── _index.js │ └── _package.json │ └── index.js ├── .eslintignore ├── .gitignore ├── .travis.yml ├── screenshot.gif ├── .yo-rc.json ├── .editorconfig ├── __tests__ └── app.js ├── CONTRIBUTING.md ├── LICENSE ├── package.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /generators/app/templates/dist/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | **/templates 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | -------------------------------------------------------------------------------- /generators/app/templates/_gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 6 4 | install: 5 | - npm install 6 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeneser/generator-vue-plugin/HEAD/screenshot.gif -------------------------------------------------------------------------------- /generators/app/templates/config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /generators/app/templates/demo/assets/_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeneser/generator-vue-plugin/HEAD/generators/app/templates/demo/assets/_logo.png -------------------------------------------------------------------------------- /generators/app/templates/_babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["es2015", { "modules": false }] 4 | ], 5 | "plugins": [ 6 | "external-helpers" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /generators/app/templates/config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "generator-node": { 3 | "promptValues": { 4 | "authorName": "jeneser", 5 | "authorEmail": "jeneserwang@gmail.com", 6 | "authorUrl": "https://github.com/jeneser" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /generators/app/templates/demo/seed/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }], 4 | "stage-2" 5 | ], 6 | "plugins": ["transform-runtime"], 7 | "comments": false, 8 | "env": { 9 | "test": { 10 | "presets": ["env", "stage-2"], 11 | "plugins": [ "istanbul" ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /generators/app/templates/demo/seed/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import Hello from '@/components/Hello' 4 | 5 | Vue.use(Router) 6 | 7 | export default new Router({ 8 | routes: [ 9 | { 10 | path: '', 11 | name: 'Hello', 12 | component: Hello 13 | } 14 | ] 15 | }) 16 | -------------------------------------------------------------------------------- /__tests__/app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var path = require('path'); 3 | var helpers = require('yeoman-test'); 4 | 5 | describe('generator-vue-plugin:app', () => { 6 | beforeAll(() => { 7 | return helpers.run(path.join(__dirname, '../generators/app')) 8 | .withPrompts({name: 'vue-plugin'}); 9 | }); 10 | 11 | it('Start test'); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /generators/app/templates/demo/seed/components/Hello.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /generators/app/templates/demo/seed/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | demo 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /generators/app/templates/_README.md: -------------------------------------------------------------------------------- 1 | # <%= name %> 2 | 3 | > <%= description %> 4 | 5 | ### Development Setup 6 | 7 | ``` bash 8 | # install deps 9 | npm install 10 | 11 | # serve demo at localhost:8080 12 | npm run dev 13 | 14 | # build library and demo 15 | npm run build 16 | 17 | # build library 18 | npm run build:library 19 | 20 | # build demo 21 | npm run build:demo 22 | ``` 23 | 24 | ## License 25 | 26 | [MIT](http://opensource.org/licenses/MIT) 27 | 28 | Copyright (c) <%= year %> <%= author %> 29 | -------------------------------------------------------------------------------- /generators/app/templates/demo/seed/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 33 | -------------------------------------------------------------------------------- /generators/app/templates/demo/_main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import App from './App' 5 | import router from './router' 6 | 7 | const <%= camelCaseName %> = process.env.NODE_ENV === 'development' 8 | ? require('../src/<%= name %>.js') 9 | : require('../dist/<%= name %>.js') 10 | 11 | Vue.config.productionTip = false 12 | 13 | // Using plugin 14 | Vue.use(<%= camelCaseName %>) 15 | 16 | /* eslint-disable no-new */ 17 | new Vue({ 18 | el: '#app', 19 | router, 20 | template: '', 21 | components: { App } 22 | }) 23 | -------------------------------------------------------------------------------- /generators/app/templates/src/_index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * <%= name %> 3 | * (c) <%= year %> <%= author %> 4 | * @license <%= license %> 5 | */ 6 | 7 | const <%= camelCaseName %> = {} 8 | 9 | /** 10 | * Plugin API 11 | */ 12 | <%= camelCaseName %>.install = function (Vue, options) { 13 | 14 | // Add global method or property 15 | Vue.myGlobalMethod = function () { 16 | // something logic ... 17 | } 18 | 19 | // Add a global asset 20 | Vue.directive('my-directive', { 21 | bind (el, binding, vnode, oldVnode) { 22 | // something logic ... 23 | } 24 | }) 25 | 26 | // Inject some component options 27 | Vue.mixin({ 28 | created: function () { 29 | // something logic ... 30 | } 31 | }) 32 | 33 | // Add an instance method 34 | Vue.prototype.$myMethod = function (options) { 35 | // something logic ... 36 | } 37 | 38 | } 39 | 40 | /** 41 | * Auto install 42 | */ 43 | if (typeof window !== 'undefined' && window.Vue) { 44 | window.Vue.use(<%= camelCaseName %>) 45 | } 46 | 47 | export default <%= camelCaseName %> 48 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | console.log(chalk.cyan(' Build complete.\n')) 30 | console.log(chalk.yellow( 31 | ' Tip: built files are meant to be served over an HTTP server.\n' + 32 | ' Opening index.html over file:// won\'t work.\n' 33 | )) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | See the [contributing docs](https://github.com/yeoman/yeoman/blob/master/contributing.md) 2 | 3 | Note: We are regularly asked whether we can add or take away features. If a change is good enough to have a positive impact on all users, we are happy to consider it. 4 | 5 | If not, `generator-vue-plugin` is fork-friendly and you can always maintain a custom version which you `npm install && npm link` to continue using via `yo vue-plugin` or a name of your choosing. 6 | 7 | ## Support Questions 8 | 9 | We frequently get issues where people *modified* something after they finished scaffolding and things weren't working properly. These are classified as **support** questions; they are related to this generator, but not something we did wrong. It's best to ask those on [Stack Overflow] with tags `#yeoman` and `#vue` instead of opening an issue here. 10 | 11 | If the issue has already been opened before it turned out to be a support question, feel free to paste the link to the Stack Overflow question, so we can answer it. 12 | 13 | [stack overflow]: http://stackoverflow.com 14 | [gitter channel]: https://gitter.im/yeoman/yeoman 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 jeneser (https://github.com/jeneser) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-vue-plugin", 3 | "version": "1.1.0", 4 | "description": "Yeoman generator generating vue plugin", 5 | "homepage": "https://github.com/jeneser/generator-vue-plugin", 6 | "author": { 7 | "name": "jeneser", 8 | "email": "jeneserwang@gmail.com", 9 | "url": "https://github.com/jeneser" 10 | }, 11 | "files": [ 12 | "generators" 13 | ], 14 | "main": "generators/index.js", 15 | "keywords": [ 16 | "generator", 17 | "vue-plugin", 18 | "vue", 19 | "yeoman-generator" 20 | ], 21 | "devDependencies": { 22 | "yeoman-test": "^1.6.0", 23 | "yeoman-assert": "^3.0.0", 24 | "nsp": "^2.6.3", 25 | "eslint": "^3.18.0", 26 | "eslint-config-xo-space": "^0.16.0", 27 | "jest": "^19.0.2", 28 | "jest-cli": "^20.0.0" 29 | }, 30 | "dependencies": { 31 | "chalk": "^1.1.3", 32 | "mkdirp": "^0.5.1", 33 | "yeoman-generator": "^1.0.0", 34 | "yosay": "^2.0.0" 35 | }, 36 | "jest": { 37 | "testEnvironment": "node" 38 | }, 39 | "scripts": { 40 | "prepublish": "nsp check", 41 | "pretest": "eslint . --fix", 42 | "test": "jest" 43 | }, 44 | "eslintConfig": { 45 | "extends": "xo-space", 46 | "env": { 47 | "jest": true, 48 | "node": true 49 | } 50 | }, 51 | "repository": "jeneser/generator-vue-plugin", 52 | "license": "MIT" 53 | } 54 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | template: 'demo/index.html', 30 | inject: true 31 | }), 32 | new FriendlyErrorsPlugin() 33 | ] 34 | }) 35 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | var shell = require('shelljs') 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | ] 16 | 17 | if (shell.which('npm')) { 18 | versionRequirements.push({ 19 | name: 'npm', 20 | currentVersion: exec('npm --version'), 21 | versionRequirement: packageConfig.engines.npm 22 | }) 23 | } 24 | 25 | module.exports = function () { 26 | var warnings = [] 27 | for (var i = 0; i < versionRequirements.length; i++) { 28 | var mod = versionRequirements[i] 29 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 30 | warnings.push(mod.name + ': ' + 31 | chalk.red(mod.currentVersion) + ' should be ' + 32 | chalk.green(mod.versionRequirement) 33 | ) 34 | } 35 | } 36 | 37 | if (warnings.length) { 38 | console.log('') 39 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 40 | console.log() 41 | for (var i = 0; i < warnings.length; i++) { 42 | var warning = warnings[i] 43 | console.log(' ' + warning) 44 | } 45 | console.log() 46 | process.exit(1) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './demo/main.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('demo') 26 | } 27 | }, 28 | module: { 29 | rules: [ 30 | { 31 | test: /\.vue$/, 32 | loader: 'vue-loader', 33 | options: vueLoaderConfig 34 | }, 35 | { 36 | test: /\.js$/, 37 | loader: 'babel-loader', 38 | include: [resolve('demo'), resolve('test')] 39 | }, 40 | { 41 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 42 | loader: 'url-loader', 43 | options: { 44 | limit: 10000, 45 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 46 | } 47 | }, 48 | { 49 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 50 | loader: 'url-loader', 51 | options: { 52 | limit: 10000, 53 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 54 | } 55 | } 56 | ] 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /generators/app/templates/build/_build.rollup.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var path = require('path') 3 | var chalk = require('chalk') 4 | var rollup = require('rollup') 5 | var babel = require('rollup-plugin-babel') 6 | var uglify = require('rollup-plugin-uglify') 7 | 8 | var version = process.env.VERSION || require('../package.json').version 9 | var author = process.env.VERSION || require('../package.json').author 10 | var license = process.env.VERSION || require('../package.json').license 11 | 12 | var banner = 13 | '/**\n' + 14 | ' * <%= name %> v' + version + '\n' + 15 | ' * (c) ' + new Date().getFullYear() + ' ' + author + '\n' + 16 | ' * @license ' + license + '\n' + 17 | ' */\n' 18 | 19 | rollup.rollup({ 20 | entry: path.resolve(__dirname, '..', 'src/<%= name %>.js'), 21 | plugins: [ 22 | babel(), 23 | uglify() 24 | ] 25 | }) 26 | .then(bundle => { 27 | return write(path.resolve(__dirname, '../dist/<%= name %>.js'), bundle.generate({ 28 | format: 'umd', 29 | moduleName: '<%= camelCaseName %>' 30 | }).code) 31 | }) 32 | .then(() => { 33 | console.log(chalk.green('\nAwesome! <%= name %> v' + version + ' builded.\n')) 34 | }) 35 | .catch(console.log) 36 | 37 | function getSize (code) { 38 | return (code.length / 1024).toFixed(2) + 'kb' 39 | } 40 | 41 | function write (dest, code) { 42 | return new Promise(function (resolve, reject) { 43 | code = banner + code 44 | fs.writeFile(dest, code, function (err) { 45 | if (err) return reject(err) 46 | console.log(chalk.blue(dest) + ' ' + getSize(code)) 47 | resolve() 48 | }) 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /generators/app/templates/config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../demo/dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../demo/dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: './', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'demo/static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # generator-vue-plugin [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] 2 | > Yeoman generator generating vue plugin :rocket: 3 | 4 |
5 |

6 | 7 |

8 |
9 | 10 | ## Features 11 | 12 | Please see our [package.json](https://github.com/jeneser/generator-vue-plugin/blob/master/package.json) for up to date information on what we support. 13 | 14 | - Build library with Rollup + Babel + Uglify 15 | - Webpack + vue-loader for single file Vue components. 16 | - State preserving hot-reload 17 | - State preserving compilation error overlay 18 | - Lint-on-save with ESLint 19 | - Source maps 20 | - JavaScript minified with UglifyJS. 21 | - HTML minified with html-minifier. 22 | - CSS across all components extracted into a single file and minified with cssnano. 23 | 24 | *For more information on what this generator can do for you, take a look at the [package.json](https://github.com/jeneser/generator-vue-plugin/blob/master/package.json) and [webpack templates](https://github.com/vuejs-templates/webpack) 25 | 26 | ## Installation 27 | 28 | First, install [Yeoman](http://yeoman.io) and generator-vue-plugin using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)). 29 | 30 | ```bash 31 | npm install -g yo 32 | npm install -g generator-vue-plugin 33 | ``` 34 | 35 | Then generate your new project: 36 | 37 | ```bash 38 | yo vue-plugin 39 | ``` 40 | 41 | ## Getting To Know Yeoman 42 | 43 | * Yeoman has a heart of gold. 44 | * Yeoman is a person with feelings and opinions, but is very easy to work with. 45 | * Yeoman can be too opinionated at times but is easily convinced not to be. 46 | * Feel free to [learn more about Yeoman](http://yeoman.io/). 47 | 48 | ## Contribute 49 | 50 | Please make sure to read the [Contributing Guide](https://github.com/jeneser/generator-vue-plugin/blob/master/CONTRIBUTING.md) before making a pull request. 51 | 52 | ## License 53 | 54 | MIT © Copyright (c) 2017 [Jeneser](https://github.com/jeneser) 55 | 56 | [npm-image]: https://badge.fury.io/js/generator-vue-plugin.svg 57 | [npm-url]: https://npmjs.org/package/generator-vue-plugin 58 | [travis-image]: https://travis-ci.org/jeneser/generator-vue-plugin.svg?branch=master 59 | [travis-url]: https://travis-ci.org/jeneser/generator-vue-plugin 60 | [daviddm-image]: https://david-dm.org/jeneser/generator-vue-plugin.svg?theme=shields.io 61 | [daviddm-url]: https://david-dm.org/jeneser/generator-vue-plugin 62 | -------------------------------------------------------------------------------- /generators/app/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= name %>", 3 | "description": "<%= description %>", 4 | "version": "0.0.0", 5 | "private": false, 6 | "main": "dist/<%= name %>.js", 7 | "files": [ 8 | "dist/*.js", 9 | "src" 10 | ], 11 | "repository": { 12 | "type": "git", 13 | "url": "<%= repository %>" 14 | }, 15 | "unpkg": "dist/<%= name %>.js", 16 | "keywords": [<% for(var i=0; i 17 | "<%= keywords[i] %>"<% if(i,<% } %><% } %> 18 | ], 19 | "author": "<%= author %>", 20 | "license": "<%= license %>", 21 | "homepage": "<%= homepage %>", 22 | "scripts": { 23 | "dev": "node build/dev-server.js", 24 | "build": "npm run build:library && npm run build:demo", 25 | "build:demo": "node build/build.js", 26 | "build:library": "node build/build.rollup.js" 27 | }, 28 | "dependencies": {}, 29 | "devDependencies": { 30 | "babel-cli": "^6.14.0", 31 | "babel-plugin-external-helpers": "^6.22.0", 32 | "babel-polyfill": "^6.13.0", 33 | "babel-preset-es2015": "^6.22.0", 34 | "babel-preset-es2015-rollup": "^1.2.0", 35 | "rollup": "^0.35.10", 36 | "rollup-plugin-babel": "^2.6.1", 37 | "rollup-plugin-uglify": "^1.0.1", 38 | "vue": "^2.3.3", 39 | "vue-router": "^2.3.1", 40 | "autoprefixer": "^6.7.2", 41 | "babel-core": "^6.22.1", 42 | "babel-loader": "^6.2.10", 43 | "babel-plugin-transform-runtime": "^6.22.0", 44 | "babel-preset-env": "^1.3.2", 45 | "babel-preset-stage-2": "^6.22.0", 46 | "babel-register": "^6.22.0", 47 | "chalk": "^1.1.3", 48 | "connect-history-api-fallback": "^1.3.0", 49 | "copy-webpack-plugin": "^4.0.1", 50 | "css-loader": "^0.28.0", 51 | "eventsource-polyfill": "^0.9.6", 52 | "express": "^4.14.1", 53 | "extract-text-webpack-plugin": "^2.0.0", 54 | "file-loader": "^0.11.1", 55 | "friendly-errors-webpack-plugin": "^1.1.3", 56 | "html-webpack-plugin": "^2.28.0", 57 | "http-proxy-middleware": "^0.17.3", 58 | "webpack-bundle-analyzer": "^2.2.1", 59 | "semver": "^5.3.0", 60 | "shelljs": "^0.7.6", 61 | "opn": "^4.0.2", 62 | "optimize-css-assets-webpack-plugin": "^1.3.0", 63 | "ora": "^1.2.0", 64 | "rimraf": "^2.6.0", 65 | "url-loader": "^0.5.8", 66 | "vue-loader": "^12.1.0", 67 | "vue-style-loader": "^3.0.1", 68 | "vue-template-compiler": "^2.3.3", 69 | "webpack": "^2.6.1", 70 | "webpack-dev-middleware": "^1.10.0", 71 | "webpack-hot-middleware": "^2.18.0", 72 | "webpack-merge": "^4.1.0" 73 | }, 74 | "engines": { 75 | "node": ">= 4.0.0", 76 | "npm": ">= 3.0.0" 77 | }, 78 | "browserslist": [ 79 | "> 1%", 80 | "last 2 versions", 81 | "not ie <= 8" 82 | ] 83 | } 84 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = require('./webpack.dev.conf') 14 | 15 | // default port where dev server listens for incoming traffic 16 | var port = process.env.PORT || config.dev.port 17 | // automatically open browser, if not set will be false 18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 19 | // Define HTTP proxies to your custom API backend 20 | // https://github.com/chimurai/http-proxy-middleware 21 | var proxyTable = config.dev.proxyTable 22 | 23 | var app = express() 24 | var compiler = webpack(webpackConfig) 25 | 26 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 27 | publicPath: webpackConfig.output.publicPath, 28 | quiet: true 29 | }) 30 | 31 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 32 | log: () => {} 33 | }) 34 | // force page reload when html-webpack-plugin template changes 35 | compiler.plugin('compilation', function (compilation) { 36 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 37 | hotMiddleware.publish({ action: 'reload' }) 38 | cb() 39 | }) 40 | }) 41 | 42 | // proxy api requests 43 | Object.keys(proxyTable).forEach(function (context) { 44 | var options = proxyTable[context] 45 | if (typeof options === 'string') { 46 | options = { target: options } 47 | } 48 | app.use(proxyMiddleware(options.filter || context, options)) 49 | }) 50 | 51 | // handle fallback for HTML5 history API 52 | app.use(require('connect-history-api-fallback')()) 53 | 54 | // serve webpack bundle output 55 | app.use(devMiddleware) 56 | 57 | // enable hot-reload and state-preserving 58 | // compilation error display 59 | app.use(hotMiddleware) 60 | 61 | // serve pure static assets 62 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 63 | app.use(staticPath, express.static('./demo/static')) 64 | 65 | var uri = 'http://localhost:' + port 66 | 67 | var _resolve 68 | var readyPromise = new Promise(resolve => { 69 | _resolve = resolve 70 | }) 71 | 72 | console.log('> Starting dev server...') 73 | devMiddleware.waitUntilValid(() => { 74 | console.log('> Listening at ' + uri + '\n') 75 | // when env is testing, don't need open it 76 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 77 | opn(uri) 78 | } 79 | _resolve() 80 | }) 81 | 82 | var server = app.listen(port) 83 | 84 | module.exports = { 85 | ready: readyPromise, 86 | close: () => { 87 | server.close() 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /generators/app/templates/build/seed/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = config.build.env 13 | 14 | var webpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ 17 | sourceMap: config.build.productionSourceMap, 18 | extract: true 19 | }) 20 | }, 21 | devtool: config.build.productionSourceMap ? '#source-map' : false, 22 | output: { 23 | path: config.build.assetsRoot, 24 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 26 | }, 27 | plugins: [ 28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 29 | new webpack.DefinePlugin({ 30 | 'process.env': env 31 | }), 32 | new webpack.optimize.UglifyJsPlugin({ 33 | compress: { 34 | warnings: false 35 | }, 36 | sourceMap: true 37 | }), 38 | // extract css into its own file 39 | new ExtractTextPlugin({ 40 | filename: utils.assetsPath('css/[name].[contenthash].css') 41 | }), 42 | // Compress extracted CSS. We are using this plugin so that possible 43 | // duplicated CSS from different components can be deduped. 44 | new OptimizeCSSPlugin({ 45 | cssProcessorOptions: { 46 | safe: true 47 | } 48 | }), 49 | // generate dist index.html with correct asset hash for caching. 50 | // you can customize output by editing /index.html 51 | // see https://github.com/ampedandwired/html-webpack-plugin 52 | new HtmlWebpackPlugin({ 53 | filename: config.build.index, 54 | template: 'demo/index.html', 55 | inject: true, 56 | minify: { 57 | removeComments: true, 58 | collapseWhitespace: true, 59 | removeAttributeQuotes: true 60 | // more options: 61 | // https://github.com/kangax/html-minifier#options-quick-reference 62 | }, 63 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 64 | chunksSortMode: 'dependency' 65 | }), 66 | // split vendor js into its own file 67 | new webpack.optimize.CommonsChunkPlugin({ 68 | name: 'vendor', 69 | minChunks: function (module, count) { 70 | // any required modules inside node_modules are extracted to vendor 71 | return ( 72 | module.resource && 73 | /\.js$/.test(module.resource) && 74 | module.resource.indexOf( 75 | path.join(__dirname, '../node_modules') 76 | ) === 0 77 | ) 78 | } 79 | }), 80 | // extract webpack runtime and module manifest to its own file in order to 81 | // prevent vendor hash from being updated whenever app bundle is updated 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'manifest', 84 | chunks: ['vendor'] 85 | }), 86 | // copy custom static assets 87 | new CopyWebpackPlugin([ 88 | { 89 | from: path.resolve(__dirname, '../demo/static'), 90 | to: config.build.assetsSubDirectory, 91 | ignore: ['.*'] 92 | } 93 | ]) 94 | ] 95 | }) 96 | 97 | if (config.build.productionGzip) { 98 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 99 | 100 | webpackConfig.plugins.push( 101 | new CompressionWebpackPlugin({ 102 | asset: '[path].gz[query]', 103 | algorithm: 'gzip', 104 | test: new RegExp( 105 | '\\.(' + 106 | config.build.productionGzipExtensions.join('|') + 107 | ')$' 108 | ), 109 | threshold: 10240, 110 | minRatio: 0.8 111 | }) 112 | ) 113 | } 114 | 115 | if (config.build.bundleAnalyzerReport) { 116 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 117 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 118 | } 119 | 120 | module.exports = webpackConfig 121 | -------------------------------------------------------------------------------- /generators/app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const Generator = require('yeoman-generator'); 4 | const chalk = require('chalk'); 5 | const yosay = require('yosay'); 6 | const mkdirp = require('mkdirp'); 7 | 8 | module.exports = class extends Generator { 9 | prompting() { 10 | // Have Yeoman greet the user. 11 | this.log(yosay( 12 | 'Welcome to the shining ' + chalk.red('generator-vue-plugin') + ' generator!' 13 | )); 14 | 15 | const prompts = [ 16 | { 17 | type: 'input', 18 | name: 'name', 19 | message: 'Your plugin name', 20 | default: 'vue-plugin' 21 | }, 22 | { 23 | type: 'input', 24 | name: 'description', 25 | message: 'Description', 26 | default: 'A vue.js plugin' 27 | }, 28 | { 29 | type: 'input', 30 | name: 'keywords', 31 | message: 'Package keywords (comma to split)', 32 | default: 'vue.js,vue-plugin' 33 | }, 34 | { 35 | type: 'input', 36 | name: 'author', 37 | message: 'Author\'s Name', 38 | default: '' 39 | }, 40 | { 41 | type: 'input', 42 | name: 'email', 43 | message: 'Author\'s Email', 44 | default: '' 45 | }, 46 | { 47 | type: 'input', 48 | name: 'repository', 49 | message: 'Project homepage url', 50 | default: '' 51 | }, 52 | { 53 | type: 'input', 54 | name: 'homepage', 55 | message: 'Author\'s Homepage', 56 | default: '' 57 | }, 58 | { 59 | type: 'input', 60 | name: 'license', 61 | message: 'License', 62 | default: 'MIT' 63 | } 64 | ]; 65 | 66 | return this.prompt(prompts).then(props => { 67 | // To access props later use this.props.someAnswer; 68 | this.props = props; 69 | }); 70 | } 71 | 72 | default() { 73 | if (path.basename(this.destinationPath()) !== this.props.name) { 74 | this.log( 75 | '\nYour generator must be inside a folder named ' + this.props.name + '\n' + 76 | 'I\'ll automatically create this folder.\n' 77 | ); 78 | mkdirp(this.props.name); 79 | this.destinationRoot(this.destinationPath(this.props.name)); 80 | } 81 | } 82 | 83 | _getCamelCaseName(name) { 84 | 85 | if (name.indexOf('-')) { 86 | let _tempName = name.toLowerCase().split('-'); 87 | 88 | for(let i = 1; i < _tempName.length; i++) { 89 | _tempName[i] = _tempName[i].substring(0, 1).toUpperCase() + 90 | _tempName[i].substring(1) 91 | } 92 | 93 | return _tempName.join('') 94 | } else { 95 | return name 96 | } 97 | 98 | } 99 | 100 | writing() { 101 | this.log('\nWriting...\n'); 102 | 103 | this._writingPackageJSON(); 104 | this._writingREADME(); 105 | this._writingBabelrc(); 106 | this._writingGitignore(); 107 | this._writingSrc(); 108 | this._writingDemo(); 109 | this._writingBuild(); 110 | this._writingConfig(); 111 | this._writingDist(); 112 | this._writingSeed(); 113 | } 114 | 115 | _writingPackageJSON() { 116 | this.fs.copyTpl( 117 | this.templatePath('_package.json'), 118 | this.destinationPath('package.json'), 119 | { 120 | name: this.props.name, 121 | description: this.props.description, 122 | keywords: this.props.keywords.split(","), 123 | author: this.props.author, 124 | email: this.props.email, 125 | repository: this.props.repository, 126 | homepage: this.props.homepage, 127 | license: this.props.license 128 | } 129 | ); 130 | } 131 | 132 | _writingREADME() { 133 | this.fs.copyTpl( 134 | this.templatePath('_README.md'), 135 | this.destinationPath('README.md'), 136 | { 137 | name: this.props.name, 138 | description: this.props.description, 139 | author: this.props.author, 140 | year: new Date().getFullYear() 141 | } 142 | ); 143 | } 144 | 145 | _writingBabelrc() { 146 | this.fs.copyTpl( 147 | this.templatePath('_babelrc'), 148 | this.destinationPath('.babelrc') 149 | ); 150 | } 151 | 152 | _writingGitignore() { 153 | this.fs.copyTpl( 154 | this.templatePath('_gitignore'), 155 | this.destinationPath('.gitignore') 156 | ); 157 | } 158 | 159 | _writingSrc() { 160 | this.fs.copyTpl( 161 | this.templatePath('src/_index.js'), 162 | this.destinationPath('src/' + this.props.name + '.js'), 163 | { 164 | name: this.props.name, 165 | author: this.props.author, 166 | license: this.props.license, 167 | camelCaseName: this._getCamelCaseName(this.props.name), 168 | year: new Date().getFullYear() 169 | } 170 | ); 171 | } 172 | 173 | _writingDemo() { 174 | 175 | mkdirp('demo/static'); 176 | 177 | this.fs.copyTpl( 178 | this.templatePath('demo/_main.js'), 179 | this.destinationPath('demo/main.js'), 180 | { 181 | name: this.props.name, 182 | camelCaseName: this._getCamelCaseName(this.props.name) 183 | } 184 | ); 185 | 186 | this.fs.copy( 187 | this.templatePath('demo/assets/_logo.png'), 188 | this.destinationPath('demo/assets/logo.png') 189 | ); 190 | } 191 | 192 | _writingBuild() { 193 | this.fs.copyTpl( 194 | this.templatePath('build/_build.rollup.js'), 195 | this.destinationPath('build/build.rollup.js'), 196 | { 197 | name: this.props.name, 198 | camelCaseName: this._getCamelCaseName(this.props.name) 199 | } 200 | ); 201 | } 202 | 203 | _writingConfig() { 204 | this.fs.copyTpl( 205 | this.templatePath('config/**'), 206 | this.destinationPath('config/') 207 | ); 208 | } 209 | 210 | _writingDist() { 211 | mkdirp('dist'); 212 | } 213 | 214 | _writingSeed() { 215 | this.fs.copyTpl( 216 | this.templatePath('build/seed/**'), 217 | this.destinationPath('build/') 218 | ); 219 | this.fs.copyTpl( 220 | this.templatePath('demo/seed/**'), 221 | this.destinationPath('demo/') 222 | ); 223 | } 224 | 225 | install() { 226 | this.log('\nInstall deps...\n'); 227 | this.installDependencies({bower: false}); 228 | } 229 | }; 230 | --------------------------------------------------------------------------------