From b4f105a46224b7f7ca7a46792b5a117c9ff83225 Mon Sep 17 00:00:00 2001 From: NewFuture Date: Tue, 14 May 2019 03:08:54 +0800 Subject: [PATCH] fix(wxss): import local & sourcemap --- src/compiler/compile-wxss.js | 2 ++ src/lib/sass.js | 12 ++++++------ test/src/app.scss | 5 +++-- test/src/assets/b.wxss.scss | 4 ++++ test/src/wxss/a.wxss | 3 +++ test/src/wxss/npm.scss | 2 ++ 6 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 test/src/assets/b.wxss.scss create mode 100644 test/src/wxss/a.wxss create mode 100644 test/src/wxss/npm.scss diff --git a/src/compiler/compile-wxss.js b/src/compiler/compile-wxss.js index be1bd8c..249878c 100644 --- a/src/compiler/compile-wxss.js +++ b/src/compiler/compile-wxss.js @@ -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"); @@ -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 })); } diff --git a/src/lib/sass.js b/src/lib/sass.js index 4ad77d7..3afac75 100644 --- a/src/lib/sass.js +++ b/src/lib/sass.js @@ -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); } @@ -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 = []; @@ -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; } @@ -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); }; diff --git a/test/src/app.scss b/test/src/app.scss index 37ba853..f133a97 100644 --- a/test/src/app.scss +++ b/test/src/app.scss @@ -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: diff --git a/test/src/assets/b.wxss.scss b/test/src/assets/b.wxss.scss new file mode 100644 index 0000000..6c75d33 --- /dev/null +++ b/test/src/assets/b.wxss.scss @@ -0,0 +1,4 @@ +.b{ + content: 'include'; + color:'red'; +} \ No newline at end of file diff --git a/test/src/wxss/a.wxss b/test/src/wxss/a.wxss new file mode 100644 index 0000000..763d5c2 --- /dev/null +++ b/test/src/wxss/a.wxss @@ -0,0 +1,3 @@ +test-a{ + scale: 0; +} \ No newline at end of file diff --git a/test/src/wxss/npm.scss b/test/src/wxss/npm.scss new file mode 100644 index 0000000..7e744dd --- /dev/null +++ b/test/src/wxss/npm.scss @@ -0,0 +1,2 @@ +@import "~weui-wxss"; +@import "~weui-wxss/dist/style/weui.wxss";