diff --git a/.gitignore b/.gitignore index d75e1f3..28ebead 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ test/unit/coverage .coveralls.yml .flowconfig docs/gitbook/_book -docs/node_modules \ No newline at end of file +docs/node_modules +site \ No newline at end of file diff --git a/build/build-docs.js b/build/build-docs.js new file mode 100644 index 0000000..ea95a50 --- /dev/null +++ b/build/build-docs.js @@ -0,0 +1,8 @@ +// https://github.com/shelljs/shelljs +const shell = require('shelljs'); + +shell.exec('gitbook build', (code, stdout, stderr) => { + if( code === 0 ) { + shell.exec('mv _book site/docs') + } +}); \ No newline at end of file diff --git a/build/build.js b/build/build.js index 6017cc6..b0b8f54 100644 --- a/build/build.js +++ b/build/build.js @@ -1,31 +1,33 @@ // https://github.com/shelljs/shelljs -require('shelljs/global') -env.NODE_ENV = 'production' +require('shelljs/global'); +env.NODE_ENV = 'production'; -var path = require('path') -var config = require('../config') -var ora = require('ora') -var webpack = require('webpack') -var webpackConfig = require('./webpack.prod.conf') +var path = require('path'); +var config = require('../config'); +var ora = require('ora'); +var webpack = require('webpack'); +var utils = require('./utils'); +var webpackConfig = utils.shouldBuildHomepage() ? require('./webpack.site.conf') : require('./webpack.prod.conf'); -var spinner = ora('building UMD module...') -spinner.start() +var text = utils.shouldBuildHomepage() ? 'homepage' : 'vue-select UMD module'; +var spinner = ora(`building ${text}...`); +spinner.start(); -var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory) -rm('-rf', assetsPath) -mkdir('-p', assetsPath) +var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory); +rm('-rf', assetsPath); +mkdir('-p', assetsPath); /** * Build the /dist/ folder */ webpack(webpackConfig, function (err, stats) { - spinner.stop() - if (err) throw err - process.stdout.write(stats.toString({ - colors: true, - modules: false, - children: false, - chunks: false, - chunkModules: false - }) + '\n') -}) \ No newline at end of file + spinner.stop(); + if (err) throw err; + process.stdout.write(stats.toString({ + colors: true, + modules: false, + children: false, + chunks: false, + chunkModules: false + }) + '\n') +}); \ No newline at end of file diff --git a/build/utils.js b/build/utils.js index 808dd4a..7b26e66 100644 --- a/build/utils.js +++ b/build/utils.js @@ -76,4 +76,8 @@ exports.styleLoaders = function (options) { */ exports.shouldServeHomepage = function () { return process.argv.indexOf('--docs') > 0 +} + +exports.shouldBuildHomepage = function () { + return process.argv.indexOf('--homepage') > 0 } \ No newline at end of file diff --git a/build/webpack.site.conf.js b/build/webpack.site.conf.js new file mode 100644 index 0000000..6ccbdde --- /dev/null +++ b/build/webpack.site.conf.js @@ -0,0 +1,82 @@ +var path = require('path') +var config = require('../config') +var utils = require('./utils') +var webpack = require('webpack') +var merge = require('webpack-merge') +var baseWebpackConfig = require('./webpack.base.conf') +var ExtractTextPlugin = require('extract-text-webpack-plugin') +var HtmlWebpackPlugin = require('html-webpack-plugin') +var env = process.env.NODE_ENV === 'testing' + ? require('../config/test.env') + : config.homepage.env + +module.exports = merge(baseWebpackConfig, { + entry: { + app: config.homepage.entry + }, + module: { + loaders: utils.styleLoaders({ sourceMap: config.homepage.productionSourceMap, extract: true }) + }, + devtool: config.homepage.productionSourceMap ? '#source-map' : false, + output: { + path: config.homepage.assetsRoot, + filename: utils.assetsPath('js/[name].[chunkhash].js'), + chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') + }, + vue: { + loaders: utils.cssLoaders({ + sourceMap: config.homepage.productionSourceMap, + extract: true + }) + }, + plugins: [ + // http://vuejs.github.io/vue-loader/workflow/production.html + new webpack.DefinePlugin({ + 'process.env': env + }), + new webpack.optimize.UglifyJsPlugin({ + compress: { + warnings: false + } + }), + new webpack.optimize.OccurenceOrderPlugin(), + // extract css into its own file + new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')), + // generate dist index.html with correct asset hash for caching. + // you can customize output by editing /index.html + // see https://github.com/ampedandwired/html-webpack-plugin + new HtmlWebpackPlugin({ + filename: 'index.html', + template: './docs/homepage/home.html', + inject: true, + minify: { + removeComments: true, + collapseWhitespace: true, + removeAttributeQuotes: true + // more options: + // https://github.com/kangax/html-minifier#options-quick-reference + }, + // necessary to consistently work with multiple chunks via CommonsChunkPlugin + chunksSortMode: 'dependency' + }), + // split vendor js into its own file + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + minChunks: function (module, count) { + // any required modules inside node_modules are extracted to vendor + return ( + module.resource && + module.resource.indexOf( + path.join(__dirname, '../node_modules') + ) === 0 + ) + } + }), + // extract webpack runtime and module manifest to its own file in order to + // prevent vendor hash from being updated whenever app bundle is updated + new webpack.optimize.CommonsChunkPlugin({ + name: 'manifest', + chunks: ['vendor'] + }) + ] +}) diff --git a/config/index.js b/config/index.js index 601fe91..704f734 100644 --- a/config/index.js +++ b/config/index.js @@ -1,5 +1,5 @@ // see http://vuejs-templates.github.io/webpack for documentation. -var path = require('path') +var path = require('path'); module.exports = { build: { @@ -17,5 +17,14 @@ module.exports = { umd: { assetsRoot: path.resolve(__dirname, '../umd'), assetsPublicPath: '/' + }, + homepage: { + env: require('./prod.env'), + entry: './docs/homepage/home.js', + assetsRoot: path.resolve(__dirname, '../site'), + assetsSubDirectory: '', + assetsPublicPath: '/', + productionSourceMap: true } -} +}; + diff --git a/package.json b/package.json index 6bf950c..c1778f6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dev:docs": "gitbook serve", "build": "node build/build.js", "build:homepage": "node build/build.js --homepage", - "build:docs": "gitbook build", + "build:docs": "yarn run build:homepage && node build/build-docs.js", "lint": "eslint --ext .js,.vue src test/unit/specs", "test": "karma start test/unit/karma.conf.js --single-run", "test-watch": "karma start test/unit/karma.conf.js --single-run=false --auto-watch=true"