@epegzz/sass-vars-loader
Advanced tools
Comparing version 1.0.3 to 1.1.0
31
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
const fs = require('fs'); | ||
const convert = require('./convert'); | ||
@@ -39,26 +40,8 @@ const loader = function(content) | ||
function jsToSass (obj) { | ||
// Convert object root properties into sass variables | ||
var sass = ''; | ||
for (var key in obj) { | ||
sass += '$' + key + ':' + JSON.stringify(obj[key]) + ';\n'; | ||
} | ||
// Store string values (so they remain unaffected) | ||
var storedStrings = []; | ||
sass = sass.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g, function (str) { | ||
var id = '___JTS' + storedStrings.length; | ||
storedStrings.push({id: id, value: str}); | ||
return id; | ||
}); | ||
// Convert js lists and objects into sass lists and maps | ||
sass = sass.replace(/[{\[]/g, '(').replace(/[}\]]/g, ')'); | ||
// Put string values back (now that we're done converting) | ||
// Remove quotes from the value | ||
storedStrings.forEach(function (str) { | ||
sass = sass.replace(str.id, str.value.replace(/['"]+/g, '')); | ||
}); | ||
const opts = { | ||
prefix: '$', | ||
suffix: ';', | ||
suffixLastItem: true, | ||
}; | ||
var sass = convert(obj, opts); | ||
return sass; | ||
@@ -65,0 +48,0 @@ } |
{ | ||
"name": "@epegzz/sass-vars-loader", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"author": "Daniel Schäfer <epegzz@gmail.com>", | ||
"description": "A SASS vars loader for Webpack. Load global SASS vars from JS/JSON files or from Webpack config.", | ||
"files": ["index.js"], | ||
"files": [ | ||
"index.js", | ||
"convert.js" | ||
], | ||
"dependencies": { | ||
@@ -14,5 +17,19 @@ "loader-utils": "~0.2.11" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"watch-test": "jest --watch" | ||
}, | ||
"keywords": [ | ||
"scss", "sass", "js", "json", "vars", "variables", "webpack", "loader" | ||
] | ||
"scss", | ||
"sass", | ||
"js", | ||
"json", | ||
"vars", | ||
"variables", | ||
"webpack", | ||
"loader" | ||
], | ||
"devDependencies": { | ||
"jest": "^18.1.0" | ||
} | ||
} |
4158
4
82
1