Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
fix(wxss): import local & sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
NewFuture committed May 13, 2019
1 parent 51b8f00 commit b4f105a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/compiler/compile-wxss.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require("path");
var gulp = require("gulp");
var sourcemaps = require("gulp-sourcemaps");
const rename = require("gulp-rename");

const sass = require("../lib/sass");
const cleanCSS = require("gulp-clean-css");
Expand Down Expand Up @@ -124,6 +125,7 @@ function compileScss(config, scssFile) {
}),
)
.pipe(config.release ? empty() : sourcemaps.write())
.pipe(rename({ extname: ".wxss" }))
.pipe(gulp.dest(config.dist))
.pipe(size({ title: TITLE, showFiles: true }));
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-d
}

if (!file.contents.length) {
file.path = replaceExtension(file.path, '.wxss'); // eslint-disable-line no-param-reassign
file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign
return cb(null, file);
}

Expand All @@ -52,8 +52,8 @@ const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-d
if (opts.includePaths) {
if (typeof opts.includePaths === 'string') {
opts.includePaths = [opts.includePaths];
}else{
opts.includePaths = opts.includePaths.map(e=>e)
} else {
opts.includePaths = opts.includePaths.map(e => e)
}
} else {
opts.includePaths = [];
Expand All @@ -63,7 +63,7 @@ const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-d

// Generate Source Maps if plugin source-map present
if (file.sourceMap) {
opts.sourceMap = file.path;
opts.sourceMap = true;
opts.omitSourceMapUrl = true;
opts.sourceMapContents = true;
}
Expand Down Expand Up @@ -100,13 +100,13 @@ const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-d
sassMap.sources = sassMap.sources.filter(src => src !== 'stdin' && src);

// Replace the map file with the original file name (but new extension)
sassMap.file = replaceExtension(sassFileSrc, '.wxss');
sassMap.file = replaceExtension(sassFileSrc, '.css');
// Apply the map
applySourceMap(file, sassMap);
}

file.contents = sassObj.css; // eslint-disable-line no-param-reassign
file.path = replaceExtension(file.path, '.wxss'); // eslint-disable-line no-param-reassign
file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign

cb(null, file);
};
Expand Down
5 changes: 3 additions & 2 deletions test/src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
app.scss
*/
//test
@import "~weui-wxss";
@import "~weui-wxss/dist/style/weui.wxss";
@import "./wxss/a.wxss"; // keep as wxss
@import "./wxss/npm.wxss"; // keep as wxss
@import "./assets/b.wxss"; // import scss
@import "./assets/a";
.t{
background:
Expand Down
4 changes: 4 additions & 0 deletions test/src/assets/b.wxss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.b{
content: 'include';
color:'red';
}
3 changes: 3 additions & 0 deletions test/src/wxss/a.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-a{
scale: 0;
}
2 changes: 2 additions & 0 deletions test/src/wxss/npm.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "~weui-wxss";
@import "~weui-wxss/dist/style/weui.wxss";

0 comments on commit b4f105a

Please # to comment.