Skip to content

Commit d3bb381

Browse files
committed
feat: css preprocessors
1 parent 88e9d46 commit d3bb381

File tree

10 files changed

+81
-12
lines changed

10 files changed

+81
-12
lines changed

packages/@vue/cli-plugin-eslint/generator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (api, { config, lintOn }) => {
77
extends: ['plugin:vue/essential']
88
},
99
devDependencies: {
10-
'eslint-plugin-vue': '^4.0.0'
10+
'eslint-plugin-vue': '^4.1.0'
1111
}
1212
}
1313

packages/@vue/cli-service/generator/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,25 @@ module.exports = (api, options) => {
4444
}
4545
})
4646
}
47+
48+
if (options.cssPreprocessor) {
49+
const deps = {
50+
sass: {
51+
'node-sass': '^4.7.2',
52+
'sass-loader': '^6.0.6'
53+
},
54+
less: {
55+
'less': '^2.7.3',
56+
'less-loader': '^4.0.5'
57+
},
58+
stylus: {
59+
'stylus': '^0.54.5',
60+
'stylus-loader': '^3.0.1'
61+
}
62+
}
63+
64+
api.extendPackage({
65+
devDependencies: deps[options.cssPreprocessor]
66+
})
67+
}
4768
}

packages/@vue/cli-service/generator/template/src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export default {
3939
margin-top: 60px;
4040
<%_ } _%>
4141
}
42-
4342
<%_ if (options.router) { _%>
43+
4444
#nav {
4545
padding: 30px;
4646
}

packages/@vue/cli-service/lib/util/CSSLoaderResolver.js

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ module.exports = class CSSLoaderResolver {
5050
*/
5151
getLoader (test, loader, options = {}) {
5252
const cssLoaderOptions = {
53-
autoprefixer: false,
5453
sourceMap: this.sourceMap,
5554
minimize: this.minimize
5655
}

packages/@vue/cli/lib/Creator.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ module.exports = class Creator {
7171
}
7272

7373
// inject core service
74-
options.plugins['@vue/cli-service'] = {
75-
projectName: name,
76-
router: options.router,
77-
vuex: options.vuex
78-
}
74+
options.plugins['@vue/cli-service'] = Object.assign({
75+
projectName: name
76+
}, options)
7977

8078
const packageManager = (
8179
cliOptions.packageManager ||

packages/@vue/cli/lib/create.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async function create (projectName, options) {
3838
'babel',
3939
'router',
4040
'vuex',
41+
'cssPreprocessors',
4142
'eslint',
4243
'unit',
4344
'e2e',

packages/@vue/cli/lib/options.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const rcPath = exports.rcPath = (
1616
const schema = createSchema(joi => joi.object().keys({
1717
router: joi.boolean(),
1818
vuex: joi.boolean(),
19-
useTaobaoRegistry: joi.any().only([true, false, null]),
19+
cssPreprocessor: joi.string().only(['sass', 'less', 'stylus']),
20+
useTaobaoRegistry: joi.boolean(),
2021
packageManager: joi.string().only(['yarn', 'npm']),
2122
plugins: joi.object().required()
2223
}))
@@ -26,7 +27,8 @@ exports.validate = options => validate(options, schema)
2627
exports.defaults = {
2728
router: false,
2829
vuex: false,
29-
useTaobaoRegistry: null,
30+
cssPreprocessor: undefined,
31+
useTaobaoRegistry: undefined,
3032
packageManager: hasYarn ? 'yarn' : 'npm',
3133
plugins: {
3234
'@vue/cli-plugin-babel': {},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = cli => {
2+
cli.injectFeature({
3+
name: 'CSS Pre-processors',
4+
value: 'css-preprocessor'
5+
})
6+
7+
cli.injectPrompt({
8+
name: 'cssPreprocessor',
9+
when: answers => answers.features.includes('css-preprocessor'),
10+
type: 'list',
11+
message: 'Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default):',
12+
choices: [
13+
{
14+
name: 'SCSS/SASS',
15+
value: 'sass'
16+
},
17+
{
18+
name: 'LESS',
19+
value: 'less'
20+
},
21+
{
22+
name: 'Stylus',
23+
value: 'stylus'
24+
}
25+
]
26+
})
27+
28+
cli.onPromptComplete((answers, options) => {
29+
if (answers.cssPreprocessor) {
30+
options.cssPreprocessor = answers.cssPreprocessor
31+
}
32+
})
33+
}

packages/@vue/cli/lib/promptModules/unit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = cli => {
1212
message: 'Pick a unit testing solution:',
1313
choices: [
1414
{
15-
name: 'Mocha (with better webpack integration, https://mochajs.org/)',
15+
name: 'Mocha via mocha-webpack (https://mochajs.org/)',
1616
value: 'mocha',
1717
short: 'Mocha'
1818
},

scripts/syncDeps.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@ const globby = require('globby')
77
const { execSync } = require('child_process')
88

99
const localPackageRE = /'(@vue\/[\w-]+)': '\^(\d+\.\d+\.\d+)'/g
10-
const npmPackageRE = /'(vue|vue-template-compiler|vuex|vue-router|vue-test-utils)': '\^(\d+\.\d+\.\d+[^']*)'/g
10+
11+
const packagesToCheck = [
12+
'vue',
13+
'vue-template-compiler',
14+
'vuex',
15+
'vue-router',
16+
'vue-test-utils',
17+
'eslint-plugin-vue',
18+
'node-sass',
19+
'sass-loader',
20+
'less',
21+
'less-loader',
22+
'stylus',
23+
'stylus-loader'
24+
]
25+
const npmPackageRE = new RegExp(`'(${packagesToCheck.join('|')})': '\\^(\\d+\\.\\d+\\.\\d+[^']*)'`)
1126

1227
;(async () => {
1328
const paths = await globby(['packages/@vue/**/*.js'])

0 commit comments

Comments
 (0)