This commit is contained in:
2022-04-07 18:09:31 +05:30
parent 36ea86d8e6
commit 1c779ef816
14095 changed files with 1769361 additions and 47 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+1
View File
@@ -0,0 +1 @@
<svg><g><path d="M0 0" /></g></svg>

After

Width:  |  Height:  |  Size: 36 B

+51
View File
@@ -0,0 +1,51 @@
/* eslint-env mocha */
'use strict'
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var gifsicle = require('imagemin-gifsicle')
var svgo = require('imagemin-svgo')
var run = require('./run-webpack')
var fixtureGif = fs.readFileSync(path.resolve(__dirname, './fixture.gif'))
var fixtureSvg = fs.readFileSync(path.resolve(__dirname, './fixture.svg'))
describe('img-loader', () => {
it('passes the img though unchanged by default', function () {
return run('./fixture.gif').then(function (image) {
assert(image.equals(fixtureGif), 'gif should be unchanged')
})
})
it('can apply optimizations for gif', function () {
return run('./fixture.gif', {
plugins: [ gifsicle({}) ]
}).then(function (image) {
assert(!image.equals(fixtureGif), 'gif should be changed')
assert(image.length < fixtureGif.length, 'optimized gif should be smaller')
})
})
it('can apply optimizations for svg', function () {
return run('./fixture.svg', {
plugins: [ svgo({}) ]
}).then(function (image) {
assert(!image.equals(fixtureSvg), 'svg should be changed')
assert(image.length < fixtureSvg.length, 'optimized svg should be smaller')
assert.strictEqual(image.toString('utf8'), '<svg/>')
})
})
it('can use a function for plugins', function () {
var context
return run('./fixture.svg', {
plugins: function (ctx) {
context = ctx
return [ svgo({}) ]
}
}).then(function (image) {
assert.strictEqual(path.basename(context.resourcePath), 'fixture.svg')
assert(image.length < fixtureSvg.length, 'optimized svg should be smaller')
})
})
})
+42
View File
@@ -0,0 +1,42 @@
'use strict'
var path = require('path')
var webpack = require('webpack')
var MemoryFS = require('memory-fs')
module.exports = function (entry, options) {
var compiler = webpack({
context: __dirname,
entry: entry,
output: {
path: path.resolve(__dirname),
filename: 'bundle.js'
},
mode: 'none',
module: {
rules: [{
test: /./,
use: [
{
loader: 'file-loader',
options: {
name: 'image'
}
},
{
loader: path.resolve(__dirname, '../index.js'),
options: options
}
]
}]
}
})
compiler.outputFileSystem = new MemoryFS()
return new Promise(function (resolve, reject) {
compiler.run(function (error, stats) {
if (!error && stats.compilation.errors.length) {
error = stats.compilation.errors[0]
}
return error ? reject(error) : resolve(stats.compilation.assets.image.source())
})
})
}