json-css-module-loader
Advanced tools
Comparing version 1.0.0 to 1.0.1
35
index.js
@@ -0,14 +1,35 @@ | ||
const path = require('path'); | ||
const JSON_EXT = '.json'; | ||
module.exports = function(source, sourceMap) { | ||
var fileName = this.resourcePath; | ||
// Remove the .json ext, will be .css / .scss / .styl etc... now | ||
// to be picked up by other loaders | ||
var cssFileName = this.resourcePath.replace(/.json$/, ''); | ||
const fileName = this.resourcePath; | ||
const formatExt = path.extname(fileName); | ||
// There can be double ext, ie. file.css.json | ||
const strippedFileName = path.basename(fileName, formatExt); | ||
const optionalSecondExt = path.extname(strippedFileName); | ||
let outputSource; | ||
let value; | ||
if (formatExt === JSON_EXT) { | ||
value = typeof source === "string" ? JSON.parse(source) : source; | ||
outputSource = `module.exports = ${JSON.stringify(value)}` | ||
} else { | ||
value = source.trim(); | ||
outputSource = value; | ||
} | ||
// Remove the extension, will be .css / .scss / .styl etc... | ||
// now to be picked up by other loaders | ||
const extRegExp = new RegExp(optionalSecondExt + formatExt + '$'); | ||
const cssFileName = fileName.replace(extRegExp, '.css'); | ||
this.cacheable && this.cacheable(); | ||
var value = typeof source === "string" ? JSON.parse(source) : source; | ||
this.value = [value]; | ||
this.value = [ value ]; | ||
var output = `require('${cssFileName}');\nmodule.exports = ${JSON.stringify(value)} ;`; | ||
var output = `require('${cssFileName}');\n${outputSource};`; | ||
return output; | ||
} |
{ | ||
"name": "json-css-module-loader", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.1.2", | ||
"sinon": "^1.17.7" | ||
}, | ||
"author": "Tom Dye", | ||
"license": "ISC" | ||
} |
# Json Css Module Loader | ||
[![Build Status](https://travis-ci.org/tomdye/json-css-module-loader.svg?branch=master)](https://travis-ci.org/tomdye/json-css-module-loader) | ||
[![npm version](https://badge.fury.io/js/json-css-module-loader.svg)](https://badge.fury.io/js/json-css-module-loader) | ||
Webpack loader to load css-module json output and the corresponding css file. | ||
@@ -27,2 +30,4 @@ ie. loading `myApp.css.json` will provide the requiring module with the css-module | ||
This loader is adapted from the [`json-loader`](https://github.com/webpack/json-loader); | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5628
10
113
1
33
2
2