diff --git a/README.md b/README.md index 684de04..cd5b516 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,4 @@ npm run dev # Build for production with minification npm run build - -# Build for production and view the bundle analyzer report -npm run build --report ``` \ No newline at end of file diff --git a/build/build.js b/build/build.js index 8c6cebd..692692b 100644 --- a/build/build.js +++ b/build/build.js @@ -1,8 +1,6 @@ 'use strict' require('./check-versions')() -process.env.NODE_ENV = 'production' - const ora = require('ora') const rm = require('rimraf') const path = require('path') @@ -10,8 +8,12 @@ const chalk = require('chalk') const webpack = require('webpack') const config = require('../config') const webpackConfig = require('./webpack.prod.conf') +var connect = require('connect') +var serveStatic = require('serve-static') -const spinner = ora('building for production...') +const spinner = ora( + 'building for ' + process.env.env_config + ' environment...' +) spinner.start() rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { @@ -30,16 +32,36 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { ) if (stats.hasErrors()) { - console.log(chalk.red(' Build failed with errors.\n')) + console.log(chalk.red(' Build failed with errors.\n')) process.exit(1) } - console.log(chalk.cyan(' Build complete.\n')) + console.log(chalk.cyan(' Build complete.\n')) console.log( chalk.yellow( - ' Tip: built files are meant to be served over an HTTP server.\n' + - " Opening index.html over file:// won't work.\n" + ' Tip: built files are meant to be served over an HTTP server.\n' + + " Opening index.html over file:// won't work.\n" ) ) + + if (process.env.npm_config_preview) { + const port = 9526 + const host = 'http://localhost:' + port + const basePath = config.build.assetsPublicPath + const app = connect() + + app.use( + basePath, + serveStatic('./dist', { + index: ['index.html', '/'] + }) + ) + + app.listen(port, function() { + console.log( + chalk.green(`> Listening at http://localhost:${port}${basePath}`) + ) + }) + } }) }) diff --git a/build/check-versions.js b/build/check-versions.js index c5c29e9..ef6f3ee 100644 --- a/build/check-versions.js +++ b/build/check-versions.js @@ -36,10 +36,10 @@ module.exports = function() { if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { warnings.push( mod.name + - ': ' + - chalk.red(mod.currentVersion) + - ' should be ' + - chalk.green(mod.versionRequirement) + ': ' + + chalk.red(mod.currentVersion) + + ' should be ' + + chalk.green(mod.versionRequirement) ) } } diff --git a/config/prod.env.js b/config/prod.env.js index 836ec67..ff4d4e7 100644 --- a/config/prod.env.js +++ b/config/prod.env.js @@ -1,5 +1,5 @@ 'use strict' module.exports = { NODE_ENV: '"production"', - BASE_API: '"https://easy-mock.com/mock/5950a2419adc231f356a6636/vue-admin"', + BASE_API: '"http://api.auauz.net"', } diff --git a/package.json b/package.json index 1943cbf..873e307 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,10 @@ "author": "Pan ", "scripts": { "dev": "cross-env BABEL_ENV=development webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", - "start": "npm run dev", - "build": "node build/build.js", - "build:report": "npm_config_report=true npm run build", + "build": "cross-env NODE_ENV=production env_config=prod node build/build.js", "lint": "eslint --ext .js,.vue src", "test": "npm run lint", + "precommit": "lint-staged", "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml" }, "repository": { diff --git a/src/components/GithubCorner/index.vue b/src/components/GithubCorner/index.vue index 726b212..6f91c5e 100644 --- a/src/components/GithubCorner/index.vue +++ b/src/components/GithubCorner/index.vue @@ -1,5 +1,5 @@