Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加vue/cli4 sass-loader v9全局注入变量教程 #5656

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/zh/guide/css.md
Expand Up @@ -135,7 +135,20 @@ module.exports = {
// `scss` 语法会要求语句结尾必须有分号,`sass` 则要求必须没有分号
// 在这种情况下,我们可以使用 `scss` 选项,对 `scss` 语法进行单独配置
scss: {
prependData: `@import "~@/variables.scss";`
// sass-loader v8语法
// prependData: `@import "~@/variables.scss";`
// sass-loader v9语法
additionalData(content, loaderContext) {
const { resourcePath, rootContext } = loaderContext;
const relativePath = path.relative(rootContext, resourcePath);
if (
relativePath.replace(/\\/g, "/") !== "src/styles/variables.scss"
) {
return '@import "~@/styles/variables.scss";' + content;
}
return content;
},

},
// 给 less-loader 传递 Less.js 相关选项
less:{
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli/bin/vue.js
Expand Up @@ -8,7 +8,7 @@ const requiredVersion = require('../package.json').engines.node
const leven = require('leven')

function checkNodeVersion (wanted, id) {
if (!semver.satisfies(process.version, wanted)) {
if (!semver.satisfies(process.version, wanted, { includePrerelease: true })) {
console.log(chalk.red(
'You are using Node ' + process.version + ', but this version of ' + id +
' requires Node ' + wanted + '.\nPlease upgrade your Node version.'
Expand Down
10 changes: 5 additions & 5 deletions packages/@vue/cli/lib/Generator.js
Expand Up @@ -6,7 +6,7 @@ const sortObject = require('./util/sortObject')
const writeFileTree = require('./util/writeFileTree')
const inferRootOptions = require('./util/inferRootOptions')
const normalizeFilePaths = require('./util/normalizeFilePaths')
const runCodemod = require('./util/runCodemod')
const { runTransformation } = require('vue-codemod')
const {
semver,

Expand Down Expand Up @@ -277,19 +277,19 @@ module.exports = class Generator {
let imports = this.imports[file]
imports = imports instanceof Set ? Array.from(imports) : imports
if (imports && imports.length > 0) {
files[file] = runCodemod(
require('./util/codemods/injectImports'),
files[file] = runTransformation(
{ path: file, source: files[file] },
require('./util/codemods/injectImports'),
{ imports }
)
}

let injections = this.rootOptions[file]
injections = injections instanceof Set ? Array.from(injections) : injections
if (injections && injections.length > 0) {
files[file] = runCodemod(
require('./util/codemods/injectOptions'),
files[file] = runTransformation(
{ path: file, source: files[file] },
require('./util/codemods/injectOptions'),
{ injections }
)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@vue/cli/lib/GeneratorAPI.js
Expand Up @@ -5,7 +5,7 @@ const deepmerge = require('deepmerge')
const resolve = require('resolve')
const { isBinaryFileSync } = require('isbinaryfile')
const mergeDeps = require('./util/mergeDeps')
const runCodemod = require('./util/runCodemod')
const { runTransformation } = require('vue-codemod')
const stringifyJS = require('./util/stringifyJS')
const ConfigTransform = require('./ConfigTransform')
const { semver, error, getPluginLink, toShortPluginId, loadModule } = require('@vue/cli-shared-utils')
Expand Down Expand Up @@ -395,12 +395,12 @@ class GeneratorAPI {
return
}

files[normalizedPath] = runCodemod(
codemod,
files[normalizedPath] = runTransformation(
{
path: this.resolve(normalizedPath),
source: files[normalizedPath]
},
codemod,
options
)
})
Expand Down
30 changes: 0 additions & 30 deletions packages/@vue/cli/lib/util/runCodemod.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/@vue/cli/package.json
Expand Up @@ -24,7 +24,6 @@
"access": "public"
},
"dependencies": {
"@babel/preset-env": "^7.9.6",
"@vue/cli-shared-utils": "^4.4.6",
"@vue/cli-ui": "^4.4.6",
"@vue/cli-ui-addon-webpack": "^4.4.6",
Expand All @@ -45,7 +44,6 @@
"isbinaryfile": "^4.0.6",
"javascript-stringify": "^1.6.0",
"js-yaml": "^3.13.1",
"jscodeshift": "^0.10.0",
"leven": "^3.1.0",
"lodash.clonedeep": "^4.5.0",
"lru-cache": "^5.1.1",
Expand All @@ -56,7 +54,7 @@
"slash": "^3.0.0",
"validate-npm-package-name": "^3.0.0",
"vue": "^2.6.11",
"vue-jscodeshift-adapter": "^2.1.0",
"vue-codemod": "^0.0.4",
"yaml-front-matter": "^3.4.1"
},
"engines": {
Expand Down