diff --git a/lib/loaders/css.js b/lib/loaders/css.js index bd9116f..415f3da 100644 --- a/lib/loaders/css.js +++ b/lib/loaders/css.js @@ -9,6 +9,19 @@ const cssModules = require("postcss-modules"); const fs = require("fs-extra"); const log = require("../logger"); const { handleError } = require("../utils"); +const through2 = require("through2"); + +function generateCssJS({ meta }) { + return through2.obj(function (file, _, cb) { + const fileName = path.basename(meta.outFile, path.extname(meta.outFile)) + ".css"; + + fs.writeFile(meta.outFile + ".js", `"use strict";require('./${fileName}');`) + .then(() => { + cb(null, file); + }) + .catch(e => cb(e)); + }); +} function isScssFile(file) { return file.extname === ".scss"; @@ -72,6 +85,15 @@ module.exports = function (stream, options, meta) { .on("error", function (err) { handleError.call(this, err, "PostCSS"); }) + .pipe( + gulpif( + file => isCssFile(file) && !isCssModule, + generateCssJS({ + meta, + esModule, + }) + ) + ) .pipe( gulpif( () => isCssModule, diff --git a/package.json b/package.json index 639e1fb..418a87c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "transform-es", - "version": "5.5.0", + "version": "5.6.0", "description": "", "keywords": [ "compile", diff --git a/test/src/css/less/_var.less b/test/src/css/less/_var.less new file mode 100644 index 0000000..fd2f2c1 --- /dev/null +++ b/test/src/css/less/_var.less @@ -0,0 +1,3 @@ +// Variables +@link-color: #428bca; // sea blue +@link-color-hover: darken(@link-color, 10%); \ No newline at end of file