更换sass库,兼容win10
parent
c611f27583
commit
64ae364fb5
|
@ -1,5 +1,10 @@
|
|||
# 更新日志
|
||||
|
||||
|
||||
## [1.1.1] 2018-12-27
|
||||
- 更换sass库,兼容win10 [#1](https://github.com/yutent/scss-to-css/issues/1)
|
||||
|
||||
|
||||
## [1.1.0] 2018-12-21
|
||||
- 增加右键菜单编译(此命令不受配置中的过滤条件限制,只判断是否scss文件)
|
||||
|
||||
|
|
10
index.js
10
index.js
|
@ -10,7 +10,7 @@ const vsc = require('vscode')
|
|||
const path = require('path')
|
||||
|
||||
const fs = require('iofs')
|
||||
const scss = require('node-sass')
|
||||
const ScssLib = require('./lib/index.js')
|
||||
const postcss = require('postcss')
|
||||
const autoprefixer = require('autoprefixer')
|
||||
let prefixer
|
||||
|
@ -19,11 +19,11 @@ const log = console.log
|
|||
|
||||
const render = function(style, file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
scss.render({ outputStyle: style, file }, (err, { css }) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
ScssLib(file, { style: ScssLib.Sass.style[style] }, res => {
|
||||
if (res && res.text) {
|
||||
resolve(res.text)
|
||||
} else {
|
||||
resolve(css)
|
||||
reject(res)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*! sass.js - v0.10.13 (7209593) - built 2018-11-19
|
||||
providing libsass 3.5.5 (39e30874)
|
||||
via emscripten 1.38.18 (7a0e274)
|
||||
*/
|
||||
var Sass = require('./sass.lib.js')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
|
||||
function fileExists(path) {
|
||||
var stat = fs.statSync(path)
|
||||
return stat && stat.isFile()
|
||||
}
|
||||
|
||||
function removeFileExtension(path) {
|
||||
return path.slice(0, path.lastIndexOf('.'))
|
||||
}
|
||||
|
||||
function importFileToSass(path, done) {
|
||||
// any path must be relative to CWD to work in both environments (real FS, and emscripten FS)
|
||||
var requestedPath = './' + path
|
||||
// figure out the *actual* path of the file
|
||||
var filesystemPath = Sass.findPathVariation(fileExists, requestedPath)
|
||||
if (!filesystemPath) {
|
||||
done({
|
||||
error: 'File "' + requestedPath + '" not found'
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Make sure to omit the ".css" file extension when it was omitted in requestedPath.
|
||||
// This allow raw css imports.
|
||||
// see https://github.com/sass/libsass/pull/754
|
||||
var isRawCss =
|
||||
!requestedPath.endsWith('.css') && filesystemPath.endsWith('.css')
|
||||
var targetPath = isRawCss
|
||||
? removeFileExtension(filesystemPath)
|
||||
: filesystemPath
|
||||
|
||||
// write the file to emscripten FS so libsass internal FS handling
|
||||
// can engage the scss/sass switch, which apparently does not happen
|
||||
// for content provided through the importer callback directly
|
||||
var content = fs.readFileSync(filesystemPath, { encoding: 'utf8' })
|
||||
Sass.writeFile(filesystemPath, content, function() {
|
||||
done({
|
||||
path: targetPath
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function importerCallback(request, done) {
|
||||
importFileToSass(resolve(request), done)
|
||||
}
|
||||
|
||||
function compileFile(path, options, callback) {
|
||||
if (!callback) {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
Sass.importer(importerCallback)
|
||||
importFileToSass(path, function() {
|
||||
Sass.compileFile(path, options, callback)
|
||||
})
|
||||
}
|
||||
|
||||
function resolve(request) {
|
||||
// the request will not have the correct "resolved" path on Windows
|
||||
// see https://github.com/medialize/sass.js/issues/69
|
||||
// see https://github.com/medialize/sass.js/issues/86
|
||||
return path
|
||||
.normalize(
|
||||
path.join(
|
||||
// sass.js works in the "/sass/" directory, make that relative to CWD
|
||||
path.dirname(request.previous.replace(/^\/sass\//, '')),
|
||||
request.current
|
||||
)
|
||||
)
|
||||
.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
compileFile.importFileToSass = importFileToSass
|
||||
compileFile.Sass = Sass
|
||||
|
||||
module.exports = compileFile
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
"name": "scss-to-css",
|
||||
"displayName": "scss-to-css",
|
||||
"description": "🔥 最简单易用的SCSS编译器, 可自动编译scss文件及补全前缀",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"publisher": "yutent",
|
||||
"author": "Yutent [@yutent]",
|
||||
"icon": "logo.png",
|
||||
|
@ -85,9 +85,8 @@
|
|||
"vscode": "^1.1.21"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-sass": "^4.10.0",
|
||||
"autoprefixer": "^9.3.1",
|
||||
"iofs": "^1.1.0",
|
||||
"postcss": "^7.0.6",
|
||||
"autoprefixer": "^9.3.1"
|
||||
"postcss": "^7.0.6"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ul{display:flex}ul li{flex:1}
|
|
@ -0,0 +1,5 @@
|
|||
ul {
|
||||
display: flex;
|
||||
|
||||
li {flex: 1}
|
||||
}
|
Loading…
Reference in New Issue