Skip to content

Commit 296fca1

Browse files
committed
update template
1 parent f103896 commit 296fca1

27 files changed

+784
-570
lines changed

meta.js

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,97 @@
1+
const path = require('path')
2+
const fs = require('fs')
3+
4+
const {
5+
sortDependencies,
6+
installDependencies,
7+
printMessage,
8+
} = require('./utils')
9+
10+
const pkg = require('./package.json')
11+
const templateVersion = pkg.version
12+
13+
114
module.exports = {
2-
"helpers": {
3-
"if_or": function (v1, v2, options) {
15+
helpers: {
16+
if_or(v1, v2, options) {
417
if (v1 || v2) {
518
return options.fn(this);
619
}
720

821
return options.inverse(this);
22+
},
23+
template_version() {
24+
return templateVersion
925
}
1026
},
11-
"prompts": {
12-
"name": {
13-
"type": "string",
14-
"required": true,
15-
"label": "Project name"
27+
prompts: {
28+
name: {
29+
type: 'string',
30+
required: true,
31+
label: 'Project name'
1632
},
17-
"description": {
18-
"type": "string",
19-
"required": true,
20-
"label": "Project description",
21-
"default": "A Vue.js project"
33+
description: {
34+
type: 'string',
35+
required: true,
36+
label: 'Project description',
37+
default: 'A Vue.js project'
2238
},
23-
"author": {
24-
"type": "string",
25-
"label": "Author"
39+
author: {
40+
type: 'string',
41+
label: 'Author'
2642
},
27-
"ie": {
28-
"type": "confirm",
29-
"message": "Support IE or older browser?"
43+
ie: {
44+
type: 'confirm',
45+
message: ' Support IE or older browser?'
3046
},
31-
"vuex": {
32-
"type": "confirm",
33-
"message": "Use vuex?"
47+
vuex: {
48+
type: 'confirm',
49+
message: 'Use vuex?'
50+
},
51+
autoInstall: {
52+
type: 'list',
53+
message:
54+
'Should we run `npm install` for you after the project has been created? (recommended)',
55+
choices: [
56+
{
57+
name: 'Yes, use NPM',
58+
value: 'npm',
59+
short: 'npm',
60+
},
61+
{
62+
name: 'Yes, use Yarn',
63+
value: 'yarn',
64+
short: 'yarn',
65+
},
66+
{
67+
name: 'No, I will handle that myself',
68+
value: false,
69+
short: 'no',
70+
},
71+
]
3472
}
3573
},
36-
"filters": {
37-
"src/components/views/todo/**/*": "vuex",
38-
"src/store/**/*": "vuex",
39-
"typings/interface/state.d.ts": "vuex"
74+
filters: {
75+
'src/components/views/todo/**/*': 'vuex',
76+
'src/store/**/*': 'vuex',
77+
'typings/interface/state.d.ts': 'vuex'
4078
},
41-
"completeMessage": "{{#inPlace}}To get started:\n\n npm install\n npm run dev.{{else}}To get started:\n\n cd {{destDirName}}\n yarn\n yarn dll\n yarn dev.{{/inPlace}}"
79+
complete(data, { chalk }) {
80+
const green = chalk.green
81+
82+
sortDependencies(data, green)
83+
const cwd = path.join(process.cwd(), data.inPlace ? '' : data.destDirName)
84+
85+
if (data.autoInstall) {
86+
installDependencies(cwd, data.autoInstall, green)
87+
.then(() => {
88+
printMessage(data, green)
89+
})
90+
.catch(e => {
91+
console.log(chalk.red('Error:'), e)
92+
})
93+
} else {
94+
printMessage(data, chalk)
95+
}
96+
}
4297
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-template-typescript",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"license": "MIT",
55
"description": "Vue use typescript",
66
"scripts": {

template/build/build.js

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,77 @@ require('./check-versions')()
22

33
process.env.NODE_ENV = 'production'
44

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(
22-
stats.toString({
23-
colors: true,
24-
modules: false,
25-
children: false,
26-
chunks: false,
27-
chunkModules: false
28-
}) + '\n\n'
29-
)
30-
31-
console.log(chalk.cyan(' Build complete.\n'))
32-
console.log(
33-
chalk.yellow(
34-
' Tip: built files are meant to be served over an HTTP server.\n' +
35-
" Opening index.html over file:// won't work.\n"
36-
)
37-
)
38-
})
39-
})
5+
const ora = require('ora')
6+
const rm = require('rimraf')
7+
const path = require('path')
8+
const chalk = require('chalk')
9+
const webpack = require('webpack')
10+
const inquirer = require('inquirer')
11+
const envList = ['doc', 'dev', 'sit', 'deploy']
12+
13+
async function build() {
14+
if (!process.env.ENV) {
15+
throw new Error('请设置 process.env.ENV')
16+
process.exit(1)
17+
}
18+
19+
if (envList.indexOf(process.env.ENV) < 0) {
20+
throw new Error('没有对应的 ENV')
21+
process.exit(1)
22+
}
23+
24+
const config = require('./config')
25+
const utils = require('./utils')
26+
27+
rm(
28+
path.join(config.build.assetsRoot, config.build.assetsSubDirectory),
29+
async err => {
30+
if (err) throw err
31+
try {
32+
let loader = utils.loading('building for dll...')
33+
const dllWebpackConfig = require('./webpack.dll.conf')
34+
await utils.runWebpack(dllWebpackConfig)
35+
loader.stop()
36+
37+
loader = utils.loading('building for production... ')
38+
const webpackConfig = require('./webpack.prod.conf')
39+
await utils.runWebpack(webpackConfig)
40+
loader.stop()
41+
42+
console.log(chalk.cyan(' Build complete.\n'))
43+
console.log(
44+
chalk.yellow(
45+
' Tip: built files are meant to be served over an HTTP server.\n' +
46+
" Opening index.html over file:// won't work.\n"
47+
)
48+
)
49+
} catch (error) {
50+
console.log(chalk.red(error))
51+
}
52+
}
53+
)
54+
}
55+
56+
if (!module.parent) {
57+
// 直接运行
58+
;(async function() {
59+
let answers = null
60+
// 如果没有指明坏境就询问
61+
if (!process.env.ENV) {
62+
answers = await inquirer.prompt([
63+
{
64+
type: 'list',
65+
name: 'env',
66+
message: '要 build 的坏境是?',
67+
choices: envList,
68+
default: 'dev'
69+
}
70+
])
71+
process.env.ENV = answers.env
72+
}
73+
build()
74+
})()
75+
} else {
76+
// 被其他模块调用
77+
module.exports = build
78+
}

template/build/config/dev.env.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var merge = require('webpack-merge')
2-
var prodEnv = require('./prod.env')
1+
'use strict'
2+
const merge = require('webpack-merge')
3+
const prodEnv = require('./prod.env')
34

45
module.exports = merge(prodEnv, {
56
NODE_ENV: '"development"'

template/build/config/index.js

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,72 @@ var path = require('path')
33
var env = process.env.ENV || 'dev'
44

55
module.exports = {
6+
dev: {
7+
// Paths
8+
assetsRoot: path.resolve(__dirname, `../../dist/${env}`),
9+
assetsSubDirectory: 'static',
10+
assetsPublicPath: '/',
11+
proxyTable: {},
12+
13+
// Various Dev Server settings
14+
host: 'localhost', // can be overwritten by process.env.HOST
15+
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
16+
autoOpenBrowser: true,
17+
errorOverlay: true,
18+
notifyOnErrors: true,
19+
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
20+
21+
// Use Eslint Loader?
22+
// If true, your code will be linted during bundling and
23+
// linting errors and warnings will be shown in the console.
24+
useEslint: true,
25+
// If true, eslint errors and warnings will also be shown in the error overlay
26+
// in the browser.
27+
showEslintErrorsInOverlay: false,
28+
29+
/**
30+
* Source Maps
31+
*/
32+
33+
// https://webpack.js.org/configuration/devtool/#development
34+
devtool: 'cheap-module-eval-source-map',
35+
36+
// If you have problems debugging vue-files in devtools,
37+
// set this to false - it *may* help
38+
// https://vue-loader.vuejs.org/en/options.html#cachebusting
39+
cacheBusting: true,
40+
41+
cssSourceMap: true
42+
},
43+
644
build: {
7-
env: require('./prod.env'),
8-
index: path.resolve(__dirname, `../../index.html`),
45+
// Template for index.html
46+
index: path.resolve(__dirname, `../../dist/${env}/index.html`),
47+
48+
// Paths
949
assetsRoot: path.resolve(__dirname, `../../dist/${env}`),
1050
assetsSubDirectory: 'static',
11-
assetsPublicPath: `/dist/${env}/`,
12-
productionSourceMap: false,
51+
assetsPublicPath: env === 'doc' ? '' : '/',
52+
53+
/**
54+
* Source Maps
55+
*/
56+
57+
productionSourceMap: true,
58+
// https://webpack.js.org/configuration/devtool/#production
59+
devtool: '#source-map',
60+
1361
// Gzip off by default as many popular static hosts such as
1462
// Surge or Netlify already gzip all static assets for you.
1563
// Before setting to `true`, make sure to:
1664
// npm install --save-dev compression-webpack-plugin
1765
productionGzip: false,
1866
productionGzipExtensions: ['js', 'css'],
67+
1968
// Run the build command with an extra argument to
2069
// View the bundle analyzer report after build finishes:
2170
// `npm run build --report`
2271
// Set to `true` or `false` to always turn it on or off
2372
bundleAnalyzerReport: process.env.npm_config_report
24-
},
25-
dev: {
26-
env: require('./dev.env'),
27-
port: 8080,
28-
autoOpenBrowser: true,
29-
assetsRoot: path.resolve(__dirname, `../../dist/${env}`),
30-
assetsSubDirectory: 'static',
31-
assetsPublicPath: '/',
32-
proxyTable: {},
33-
// CSS Sourcemaps off by default because relative paths are "buggy"
34-
// with this option, according to the CSS-Loader README
35-
// (https://github.com/webpack/css-loader#sourcemaps)
36-
// In our experience, they generally work as expected,
37-
// just be aware of this issue when enabling this option.
38-
cssSourceMap: false
3973
}
4074
}

template/build/config/prod.env.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
module.exports = {
24
NODE_ENV: '"production"'
35
}

template/build/dev-client.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)