Skip to content

Commit 8596eeb

Browse files
committed
Merge branch 'develop' into feature/stylint
2 parents 8593d5b + cd4d7d9 commit 8596eeb

23 files changed

+451
-235
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ node_modules
22
.DS_Store
33
docs/_book
44
test/
5+
node_modules
6+
.DS_Store
7+
docs/_book
8+
test/

docs/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [Project Structure](structure.md)
44
- [Build Commands](commands.md)
5+
- [Babel Configuration](babel.md)
56
- [Linter Configuration](linter.md)
67
- [Pre-Processors](pre-processors.md)
78
- [Handling Static Assets](static.md)

docs/babel.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Babel Configuration
2+
3+
This boilerplate uses [`babel-preset-env`](https://www.npmjs.com/package/babel-preset-env) for configuring babel. You can read more about it here - http://2ality.com/2017/02/babel-preset-env.html.
4+
5+
> A Babel preset that compiles ES2015+ down to ES5 by automatically determining the Babel plugins and polyfills you need based on your targeted browser or runtime environments.
6+
7+
It uses [`browserslist`](https://github.com./ai/browserslist) to parse this information, so we can use any [valid query format supported by `browserslist`](https://github.com./ai/browserslist#queries).
8+
9+
However there is a caveat. `browserslist` recommends defining the target in a common place like `package.json` or in a `.browserslistrc` config file. This allows tools like [`autoprefixer`](https://github.com./postcss/autoprefixer) and [`eslint-plugin-compat`](https://github.com./amilajack/eslint-plugin-compat) to share the config. For this template, `browserslist` is configured in the `package.json`:
10+
11+
```json
12+
{
13+
"...": "...",
14+
"browserslist": [
15+
"> 1%",
16+
"last 2 versions",
17+
"not ie <= 8"
18+
]
19+
}
20+
```
21+
22+
But the latest stable release of `babel-preset-env`, `v1.6.1` does not support loading the config from `package.json`. So the target environment is repeated in `.babelrc`. If you wish to change your target environment, please be sure to update both `package.json` and `.babelrc`. Note that this has been fixed in the beta version([`@babel/[email protected]`](https://github.com./babel/babel/tree/master/packages/babel-preset-env)) and the template will be updated once it is out of beta.

meta.js

+163-137
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,205 @@
1-
const path = require('path');
2-
const fs = require('fs');
3-
4-
function sortObject(object) {
5-
// Based on https://github.com./yarnpkg/yarn/blob/v1.3.2/src/config.js#L79-L85
6-
const sortedObject = {};
7-
Object.keys(object).sort().forEach(item => {
8-
sortedObject[item] = object[item];
9-
});
10-
return sortedObject;
11-
}
1+
const path = require('path')
2+
const fs = require('fs')
3+
const {
4+
sortDependencies,
5+
installDependencies,
6+
runLintFix,
7+
printMessage,
8+
} = require('./utils')
129

1310
module.exports = {
14-
"helpers": {
15-
"if_or": function (v1, v2, options) {
11+
helpers: {
12+
if_or: function(v1, v2, options) {
1613
if (v1 || v2) {
17-
return options.fn(this);
14+
return options.fn(this)
1815
}
1916

20-
return options.inverse(this);
21-
}
17+
return options.inverse(this)
18+
},
2219
},
23-
"prompts": {
24-
"name": {
25-
"type": "string",
26-
"required": true,
27-
"message": "Project name"
20+
prompts: {
21+
name: {
22+
type: 'string',
23+
required: true,
24+
message: 'Project name',
2825
},
29-
"description": {
30-
"type": "string",
31-
"required": false,
32-
"message": "Project description",
33-
"default": "A Vue.js project"
26+
description: {
27+
type: 'string',
28+
required: false,
29+
message: 'Project description',
30+
default: 'A Vue.js project',
3431
},
35-
"author": {
36-
"type": "string",
37-
"message": "Author"
32+
author: {
33+
type: 'string',
34+
message: 'Author',
3835
},
39-
"build": {
40-
"type": "list",
41-
"message": "Vue build",
42-
"choices": [
36+
build: {
37+
type: 'list',
38+
message: 'Vue build',
39+
choices: [
4340
{
44-
"name": "Runtime + Compiler: recommended for most users",
45-
"value": "standalone",
46-
"short": "standalone"
41+
name: 'Runtime + Compiler: recommended for most users',
42+
value: 'standalone',
43+
short: 'standalone',
4744
},
4845
{
49-
"name": "Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere",
50-
"value": "runtime",
51-
"short": "runtime"
52-
}
53-
]
46+
name:
47+
'Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere',
48+
value: 'runtime',
49+
short: 'runtime',
50+
},
51+
],
5452
},
55-
"router": {
56-
"type": "confirm",
57-
"message": "Install vue-router?"
53+
router: {
54+
type: 'confirm',
55+
message: 'Install vue-router?',
5856
},
59-
"eslint": {
60-
"type": "confirm",
61-
"message": "Use ESLint to lint your code?"
57+
eslint: {
58+
type: 'confirm',
59+
message: 'Use ESLint to lint your code?',
6260
},
63-
"eslintConfig": {
64-
"when": "eslint",
65-
"type": "list",
66-
"message": "Pick an ESLint preset",
67-
"choices": [
61+
eslintConfig: {
62+
when: 'eslint',
63+
type: 'list',
64+
message: 'Pick an ESLint preset',
65+
choices: [
6866
{
69-
"name": "Standard (https://github.com./standard/standard)",
70-
"value": "standard",
71-
"short": "Standard"
67+
name: 'Standard (https://github.com./standard/standard)',
68+
value: 'standard',
69+
short: 'Standard',
7270
},
7371
{
74-
"name": "Airbnb (https://github.com./airbnb/javascript)",
75-
"value": "airbnb",
76-
"short": "Airbnb"
72+
name: 'Airbnb (https://github.com./airbnb/javascript)',
73+
value: 'airbnb',
74+
short: 'Airbnb',
7775
},
7876
{
79-
"name": "none (configure it yourself)",
80-
"value": "none",
81-
"short": "none"
77+
name: 'none (configure it yourself)',
78+
value: 'none',
79+
short: 'none'
8280
}
8381
]
8482
},
85-
"stylelint": {
86-
"type": "confirm",
87-
"message": "Use stylelint to lint your code?"
83+
stylelint: {
84+
type: 'confirm',
85+
message: 'Use stylelint to lint your code?'
8886
},
89-
"stylelintConfig": {
90-
"when": "stylelint",
91-
"type": "list",
92-
"message": "Pick a stylelint preset",
93-
"choices": [
87+
stylelintConfig: {
88+
when: 'stylelint',
89+
type: 'list',
90+
message: 'Pick a stylelint preset',
91+
choices: [
9492
{
95-
"name": "Standard (https://github.com./stylelint/stylelint-config-standard)",
96-
"value": "standard",
97-
"short": "Standard"
93+
name: 'Standard (https://github.com./stylelint/stylelint-config-standard)',
94+
value: 'standard',
95+
short: 'Standard'
9896
},
9997
{
100-
"name": "Recommended (https://github.com./stylelint/stylelint-config-recommended)",
101-
"value": "recommended",
102-
"short": "Recommended"
98+
name: 'Recommended (https://github.com./stylelint/stylelint-config-recommended)',
99+
value: 'recommended',
100+
short: 'Recommended'
103101
},
104102
{
105-
"name": "Wikimedia (https://github.com./wikimedia/stylelint-config-wikimedia)",
106-
"value": "wikimedia",
107-
"short": "Wikimedia"
103+
name: 'Wikimedia (https://github.com./wikimedia/stylelint-config-wikimedia)',
104+
value: 'wikimedia',
105+
short: 'Wikimedia'
108106
},
109107
{
110-
"name": "none (configure it yourself)",
111-
"value": "none",
112-
"short": "none"
113-
}
114-
]
108+
name: 'none (configure it yourself)',
109+
value: 'none',
110+
short: 'none',
111+
},
112+
],
115113
},
116-
"unit": {
117-
"type": "confirm",
118-
"message": "Set up unit tests"
114+
unit: {
115+
type: 'confirm',
116+
message: 'Set up unit tests',
119117
},
120-
"runner": {
121-
"when": "unit",
122-
"type": "list",
123-
"message": "Pick a test runner",
124-
"choices": [
118+
runner: {
119+
when: 'unit',
120+
type: 'list',
121+
message: 'Pick a test runner',
122+
choices: [
125123
{
126-
"name": "Jest",
127-
"value": "jest",
128-
"short": "jest"
124+
name: 'Jest',
125+
value: 'jest',
126+
short: 'jest',
129127
},
130128
{
131-
"name": "Karma and Mocha",
132-
"value": "karma",
133-
"short": "karma"
129+
name: 'Karma and Mocha',
130+
value: 'karma',
131+
short: 'karma',
134132
},
135133
{
136-
"name": "none (configure it yourself)",
137-
"value": "noTest",
138-
"short": "noTest"
139-
}
140-
]
134+
name: 'none (configure it yourself)',
135+
value: 'noTest',
136+
short: 'noTest',
137+
},
138+
],
139+
},
140+
e2e: {
141+
type: 'confirm',
142+
message: 'Setup e2e tests with Nightwatch?',
143+
},
144+
autoInstall: {
145+
type: 'list',
146+
message:
147+
'Should we run `npm install` for you after the project has been created? (recommended)',
148+
choices: [
149+
{
150+
name: 'Yes, use NPM',
151+
value: 'npm',
152+
short: 'npm',
153+
},
154+
{
155+
name: 'Yes, use Yarn',
156+
value: 'yarn',
157+
short: 'yarn',
158+
},
159+
{
160+
name: 'No, I will handle that myself',
161+
value: false,
162+
short: 'no',
163+
},
164+
],
141165
},
142-
"e2e": {
143-
"type": "confirm",
144-
"message": "Setup e2e tests with Nightwatch?"
145-
}
146166
},
147-
"filters": {
148-
".eslintrc.js": "eslint",
149-
".eslintignore": "eslint",
150-
".stylelintrc.js": "stylelint",
151-
".stylelintignore": "stylelint",
152-
"config/test.env.js": "unit || e2e",
153-
"build/webpack.test.conf.js": "unit && runner === 'karma'",
154-
"test/unit/**/*": "unit",
155-
"test/unit/index.js": "unit && runner === 'karma'",
156-
"test/unit/jest.conf.js": "unit && runner === 'jest'",
157-
"test/unit/karma.conf.js": "unit && runner === 'karma'",
158-
"test/unit/specs/index.js": "unit && runner === 'karma'",
159-
"test/unit/setup.js": "unit && runner === 'jest'",
160-
"test/e2e/**/*": "e2e",
161-
"src/router/**/*": "router"
167+
filters: {
168+
'.eslintrc.js': 'eslint',
169+
'.eslintignore': 'eslint',
170+
'.stylelintrc.js': 'stylelint',
171+
'.stylelintignore': 'stylelint',
172+
'config/test.env.js': 'unit || e2e',
173+
'build/webpack.test.conf.js': "unit && runner === 'karma'",
174+
'test/unit/**/*': 'unit',
175+
'test/unit/index.js': "unit && runner === 'karma'",
176+
'test/unit/jest.conf.js': "unit && runner === 'jest'",
177+
'test/unit/karma.conf.js': "unit && runner === 'karma'",
178+
'test/unit/specs/index.js': "unit && runner === 'karma'",
179+
'test/unit/setup.js': "unit && runner === 'jest'",
180+
'test/e2e/**/*': 'e2e',
181+
'src/router/**/*': 'router',
162182
},
163-
"complete": function (data) {
164-
const packageJsonFile = path.join(
165-
data.inPlace ? "" : data.destDirName,
166-
"package.json"
167-
);
168-
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile));
169-
packageJson.devDependencies = sortObject(packageJson.devDependencies);
170-
packageJson.dependencies = sortObject(packageJson.dependencies);
171-
fs.writeFileSync(
172-
packageJsonFile,
173-
JSON.stringify(packageJson, null, 2) + "\n"
174-
);
183+
complete: function(data, { chalk }) {
184+
const green = chalk.green
185+
186+
sortDependencies(data, green)
187+
188+
const cwd = path.join(process.cwd(), data.inPlace ? '' : data.destDirName)
175189

176-
const message = `To get started:\n\n ${data.inPlace ? '' : `cd ${data.destDirName}\n `}npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack`;
177-
console.log("\n" + message.split(/\r?\n/g).map(line => " " + line).join("\n"));
178-
}
179-
};
190+
if (data.autoInstall) {
191+
installDependencies(cwd, data.autoInstall, green)
192+
.then(() => {
193+
return runLintFix(cwd, data, green)
194+
})
195+
.then(() => {
196+
printMessage(data, green)
197+
})
198+
.catch(e => {
199+
console.log(chalk.red('Error:'), e)
200+
})
201+
} else {
202+
printMessage(data, chalk)
203+
}
204+
},
205+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-template-webpack",
3-
"version": "1.2.5",
3+
"version": "1.2.7",
44
"license": "MIT",
55
"description": "A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.",
66
"scripts": {

0 commit comments

Comments
 (0)