--- install scripts ---
### prepublishOnly
npm run build
--- package.json (entry) ---
{
"name": "jest-url-loader",
"version": "0.1.0",
"description": "Similar with webpack's url-loader for Jest.",
"license": "MIT",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"clean": "rimraf -rf lib",
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
"lint-staged": "lint-staged",
"test": "jest",
"ci": "npm run lint && npm run test && lint-md .",
"start": "tsc -w",
"build": "rimraf ./lib && tsc --module commonjs --outDir lib",
"prepublishOnly": "npm run build"
},
"dependencies": {
"mime": "^2.4.4"
},
"peerDependencies": {},
"keywords": [
"jest-transformer",
"url-loader",
"image",
"svg",
"png",
"jpg"
],
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.17",
"@typescript-eslint/eslint-plugin": "^2.3.1",
"@typescript-eslint/parser": "^2.3.1",
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"husky": "^3.0.5",
"jest": "^24.9.0",
"jest-electron": "^0.1.7",
"lint-md-cli": "^0.1.1",
"lint-staged": "^9.3.0",
"prettier": "^1.18.2",
"rimraf": "^3.0.0",
"ts-jest": "^24.1.0",
--- index.js (entry) ---
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var mime_1 = __importDefault(require("mime"));
/**
* the transformer entry
* @type {{process(*=): *}}
*/
module.exports = {
/**
* @param src file content string
* @param filename file path
* @param config jest config
* @param options transformer options
*/
process: function (src, filename, config, options) {
var mimeType = options.mimetype || mime_1.default.getType(filename);
// read binary data
var bitmap = fs.readFileSync(filename);
// convert binary data
var buf = new Buffer(bitmap);
return "module.exports = " + JSON.stringify("data:" + (mimeType || '') + ";base64," + bu{
"name": "jest-url-loader",
"version": "0.1.0",
"description": "Similar with webpack's url-loader for Jest.",
"license": "MIT",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"clean": "rimraf -rf lib",
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
"lint-staged": "lint-staged",
"test": "jest",
"ci": "npm run lint && npm run test && lint-md .",
"start": "tsc -w",
"build": "rimraf ./lib && tsc --module commonjs --outDir lib",
"prepublishOnly": "npm run build"
},
"dependencies": {
"mime": "^2.4.4"
},
"peerDependencies": {},
"keywords": [
"jest-transformer",
"url-loader",
"image",
"svg",
"png",
"jpg"
],
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.17",
"@typescript-eslint/eslint-plugin": "^2.3.1",
"@typescript-eslint/parser": "^2.3.1",
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"husky": "^3.0.5",
"jest": "^24.9.0",
"jest-electron": "^0.1.7",
"lint-md-cli": "^0.1.1",
"lint-staged": "^9.3.0",
"prettier": "^1.18.2",
"rimraf": "^3.0.0",
"ts-jest": "^24.1.0",
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var mime_1 = __importDefault(require("mime"));
/**
* the transformer entry
* @type {{process(*=): *}}
*/
module.exports = {
/**
* @param src file content string
* @param filename file path
* @param config jest config
* @param options transformer options
*/
process: function (src, filename, config, options) {
var mimeType = options.mimetype || mime_1.default.getType(filename);
// read binary data
var bitmap = fs.readFileSync(filename);
// convert binary data
var buf = new Buffer(bitmap);
return "module.exports = " + JSON.stringify("data:" + (mimeType || '') + ";base64," + bu