Skip to content

Commit

Permalink
feat: css preprocessors
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 8, 2018
1 parent 88e9d46 commit d3bb381
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-eslint/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (api, { config, lintOn }) => {
extends: ['plugin:vue/essential']
},
devDependencies: {
'eslint-plugin-vue': '^4.0.0'
'eslint-plugin-vue': '^4.1.0'
}
}

Expand Down
21 changes: 21 additions & 0 deletions packages/@vue/cli-service/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ module.exports = (api, options) => {
}
})
}

if (options.cssPreprocessor) {
const deps = {
sass: {
'node-sass': '^4.7.2',
'sass-loader': '^6.0.6'
},
less: {
'less': '^2.7.3',
'less-loader': '^4.0.5'
},
stylus: {
'stylus': '^0.54.5',
'stylus-loader': '^3.0.1'
}
}

api.extendPackage({
devDependencies: deps[options.cssPreprocessor]
})
}
}
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/generator/template/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default {
margin-top: 60px;
<%_ } _%>
}
<%_ if (options.router) { _%>
#nav {
padding: 30px;
}
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli-service/lib/util/CSSLoaderResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ module.exports = class CSSLoaderResolver {
*/
getLoader (test, loader, options = {}) {
const cssLoaderOptions = {
autoprefixer: false,
sourceMap: this.sourceMap,
minimize: this.minimize
}
Expand Down
8 changes: 3 additions & 5 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ module.exports = class Creator {
}

// inject core service
options.plugins['@vue/cli-service'] = {
projectName: name,
router: options.router,
vuex: options.vuex
}
options.plugins['@vue/cli-service'] = Object.assign({
projectName: name
}, options)

const packageManager = (
cliOptions.packageManager ||
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function create (projectName, options) {
'babel',
'router',
'vuex',
'cssPreprocessors',
'eslint',
'unit',
'e2e',
Expand Down
6 changes: 4 additions & 2 deletions packages/@vue/cli/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const rcPath = exports.rcPath = (
const schema = createSchema(joi => joi.object().keys({
router: joi.boolean(),
vuex: joi.boolean(),
useTaobaoRegistry: joi.any().only([true, false, null]),
cssPreprocessor: joi.string().only(['sass', 'less', 'stylus']),
useTaobaoRegistry: joi.boolean(),
packageManager: joi.string().only(['yarn', 'npm']),
plugins: joi.object().required()
}))
Expand All @@ -26,7 +27,8 @@ exports.validate = options => validate(options, schema)
exports.defaults = {
router: false,
vuex: false,
useTaobaoRegistry: null,
cssPreprocessor: undefined,
useTaobaoRegistry: undefined,
packageManager: hasYarn ? 'yarn' : 'npm',
plugins: {
'@vue/cli-plugin-babel': {},
Expand Down
33 changes: 33 additions & 0 deletions packages/@vue/cli/lib/promptModules/cssPreprocessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = cli => {
cli.injectFeature({
name: 'CSS Pre-processors',
value: 'css-preprocessor'
})

cli.injectPrompt({
name: 'cssPreprocessor',
when: answers => answers.features.includes('css-preprocessor'),
type: 'list',
message: 'Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default):',
choices: [
{
name: 'SCSS/SASS',
value: 'sass'
},
{
name: 'LESS',
value: 'less'
},
{
name: 'Stylus',
value: 'stylus'
}
]
})

cli.onPromptComplete((answers, options) => {
if (answers.cssPreprocessor) {
options.cssPreprocessor = answers.cssPreprocessor
}
})
}
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/promptModules/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = cli => {
message: 'Pick a unit testing solution:',
choices: [
{
name: 'Mocha (with better webpack integration, https://mochajs.org/)',
name: 'Mocha via mocha-webpack (https://mochajs.org/)',
value: 'mocha',
short: 'Mocha'
},
Expand Down
17 changes: 16 additions & 1 deletion scripts/syncDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ const globby = require('globby')
const { execSync } = require('child_process')

const localPackageRE = /'(@vue\/[\w-]+)': '\^(\d+\.\d+\.\d+)'/g
const npmPackageRE = /'(vue|vue-template-compiler|vuex|vue-router|vue-test-utils)': '\^(\d+\.\d+\.\d+[^']*)'/g

const packagesToCheck = [
'vue',
'vue-template-compiler',
'vuex',
'vue-router',
'vue-test-utils',
'eslint-plugin-vue',
'node-sass',
'sass-loader',
'less',
'less-loader',
'stylus',
'stylus-loader'
]
const npmPackageRE = new RegExp(`'(${packagesToCheck.join('|')})': '\\^(\\d+\\.\\d+\\.\\d+[^']*)'`)

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

0 comments on commit d3bb381

Please sign in to comment.