Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-webp-loader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-webp-loader - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.idea/jsLibraryMappings.xml

56

index.js

@@ -5,27 +5,39 @@ Object.defineProperty(exports, "__esModule", {

exports.raw = true
exports.default = loader
var loaderUtils = require('loader-utils')
var schemaUtils = require('schema-utils')
var _loaderUtils2 = _interopRequireDefault(loaderUtils);
const fs = require('fs')
const {resolve} = require('path')
const loaderUtils = require('loader-utils')
const _loaderUtils = loaderUtils['__esModule'] ? loaderUtils : {default: loaderUtils}
const imagemin = require('imagemin')
const imageminWebp = require('imagemin-webp')
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function loader(content) {
var options = loaderUtils.getOptions(this) || {}
// 获取hash
console.log(loaderUtils.getHashDigest(content) + '-----------------')
var url = _loaderUtils2.default.interpolateName(this, options.name, {
content,
regExp: options.regExp
exports.default = function (content) {
const options = loaderUtils.getOptions(this) || {}
const hasHash = /\[hash.*?\]/.test(options.name) ? 1 : 0
const url = _loaderUtils.default.interpolateName(this, options.name, {content, regExp: options.regExp})
this.emitFile(url, content)
this.targetFilePath = url
const webpPath = options.name ? /[\//]/.test(options.name) ? url.match(/.*[\//]/)[0] : './' : './'
imagemin([this.resourcePath], resolve(options.outputPath, webpPath), {
use: [imageminWebp({quality: 90})]
}).then(back => {
if (hasHash) {
let webpPath = back[0].path
const hash = url.match(/\.[^.]+(?=\.(png|jpe?g))/i)[0].substr(1)
let newPath = webpPath.replace(/\.webp$/g, "." + hash) + '.webp'
fs.rename(webpPath, newPath, error => error && console.log(error))
}
})
this.emitFile(url, content)
return `module.exports = __webpack_public_path__ + ${JSON.stringify(url)}`
let publicPath = url
if (options.publicPath) {
if (/\/$/.test(options.publicPath)) {
publicPath = options.publicPath + publicPath
} else {
publicPath = options.publicPath + '/' + publicPath
}
}
if (options.requestType) {
publicPath = publicPath.replace(/\.(webp|png|jpe?g)/, '.' + options.requestType)
}
return `module.exports = __webpack_public_path__ + ${JSON.stringify(publicPath)};`
}
{
"name": "image-webp-loader",
"version": "0.0.1",
"version": "0.0.2",
"description": "With webpack-loader to convert ordinary picture format to webp pictures, you can produce original pictures and webp pictures together and keep the same hash",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development"
"test": "rimraf test/dist&&webpack --config test/webpack.config.js --mode development"
},

@@ -13,4 +13,9 @@ "repository": {

},
"author": "liujianhua",
"author": "jianhualiu",
"license": "MIT",
"keywords": [
"webp",
"webpack",
"loader"
],
"bugs": {

@@ -21,2 +26,4 @@ "url": "https://github.com/grajs/image-webp-loader/issues"

"devDependencies": {
"imagemin": "^5.3.1",
"imagemin-webp": "^4.1.0",
"webpack": "^4.7.0",

@@ -23,0 +30,0 @@ "webpack-cli": "^2.1.3"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc