Skip to content

Commit

Permalink
refactor: removed noquotes option, defaulting it to true
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `noquotes` loader option has been removed. See #126 for more details and rationale behind that change.
  • Loading branch information
bhovhannes committed Jun 29, 2019
1 parent fad1091 commit b2fe25b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 65 deletions.
10 changes: 1 addition & 9 deletions README.md
Expand Up @@ -16,11 +16,6 @@ Parameters can be passed both in a url or from webpack config file. See [Loaders

The loader supports the following parameters:

### `noquotes`

Passing this parameter (or setting to `true`) tells to loader *not to include* resulting string in quotes. This can be useful if one wants to use data-url for SVG image as a value for JavaScript variable.


### `limit`

If given will tell the loader not to encode the source file if its content is greater than this limit.
Expand Down Expand Up @@ -72,10 +67,7 @@ require('svg-url-loader?encoding=base64!./file.svg');
### In JS:
``` javascript
require('svg-url-loader!./file.svg');
// => DataUrl for file.svg, enclosed in quotes

require('svg-url-loader?noquotes!./file.svg');
// => DataUrl for file.svg, without quotes
// => DataUrl for file.svg
```

### In CSS (with webpack.config.js below):
Expand Down
6 changes: 3 additions & 3 deletions src/loader.js
Expand Up @@ -46,9 +46,9 @@ module.exports = function(content) {
}

if (!(query.iesafe && hasStyleElement && data.length > 4096)) {
if (query.encoding === "none" && !query.noquotes) {
data = '"'+data+'"';
}
// if (query.encoding === "none" && !query.noquotes) {
// data = '"'+data+'"';
// }

return 'module.exports = ' + JSON.stringify(data);
}
Expand Down
57 changes: 4 additions & 53 deletions test/loader.spec.js
Expand Up @@ -44,48 +44,6 @@ describe('svg-url-loader', function() {
})


describe('"noquotes" option', function () {
it('should convert SVG file to utf-8 encoded data-uri string, enclosed in quotes', function(done) {
const config = {
...getBaseWebpackConfig(),
entry: './test/input/icon.js'
}
config.module.rules[0].use[0].options.noquotes = false
webpack(config, function(err) {
expect(err).toBeNull()
fs.readFile(getBundleFile(), function(err, data) {
expect(err).toBeNull()
const encoded = eval(data.toString())
expect(encoded.indexOf('"')).toBe(0)
expect(encoded.lastIndexOf('"')).toBe(encoded.length - 1)
expect(encoded.indexOf('data:image/svg+xml,%3Csvg')).toBe(1)
return done()
})
})
})


it('should not enclose output in quotes if \'noquotes\' option is specified', function(done) {
const config = {
...getBaseWebpackConfig(),
entry: './test/input/icon.js'
}
config.module.rules[0].use[0].options.noquotes = true

webpack(config, function(err) {
expect(err).toBeNull()
fs.readFile(getBundleFile(), function(err, data) {
expect(err).toBeNull()
const encoded = eval(data.toString())
expect(encoded.indexOf('data:image/svg+xml,%3Csvg')).toBe(0)
expect(encoded.lastIndexOf('svg%3E')).toBe(encoded.length - 'svg%3E'.length)
return done()
})
})
})
})


describe('"stripdeclarations" option', function () {
it('if turned off - should do nothing to an SVG that has an XML declaration', function(done) {
const config = {
Expand Down Expand Up @@ -117,9 +75,7 @@ describe('svg-url-loader', function() {
fs.readFile(getBundleFile(), function(err, data) {
expect(err).toBeNull()
const encoded = eval(data.toString())
expect(encoded.indexOf('"')).toBe(0)
expect(encoded.lastIndexOf('"')).toBe(encoded.length - 1)
expect(encoded.indexOf('data:image/svg+xml,%3Csvg')).toBe(1)
expect(encoded.indexOf('data:image/svg+xml,%3Csvg')).toBe(0)
return done()
})
})
Expand All @@ -139,7 +95,7 @@ describe('svg-url-loader', function() {
expect(err).toBeNull()
const encoded = eval(data.toString())
expect(encoded.indexOf('%3C?xml version="1.0" encoding="UTF-8"?%3E')).toBe(-1)
expect(encoded.indexOf('data:image/svg+xml,%3Csvg')).toBe(1)
expect(encoded.indexOf('data:image/svg+xml,%3Csvg')).toBe(0)
return done()
})
})
Expand Down Expand Up @@ -176,7 +132,6 @@ describe('svg-url-loader', function() {
...getBaseWebpackConfig(),
entry: './test/input/less.js'
}
config.module.rules[0].use[0].options.noquotes = false
config.module.rules.push({
test: /\.less$/,
use: [
Expand Down Expand Up @@ -209,7 +164,6 @@ describe('svg-url-loader', function() {
...getBaseWebpackConfig(),
entry: './test/input/scss.js'
}
config.module.rules[0].use[0].options.noquotes = false
config.module.rules.push({
test: /\.scss$/,
use: [
Expand Down Expand Up @@ -242,7 +196,6 @@ describe('svg-url-loader', function() {
...getBaseWebpackConfig(),
entry: './test/input/css.js'
}
config.module.rules[0].use[0].options.noquotes = false
config.module.rules.push({
test: /\.css$/,
use: [
Expand Down Expand Up @@ -276,8 +229,7 @@ describe('svg-url-loader', function() {
entry: './test/input/4047B-encoded-styled.js'
}
config.module.rules[0].use[0].options.iesafe = true
config.module.rules[0].use[0].options.noquotes = true


webpack(config, function(err) {
expect(err).toBeNull()
fs.readFile(getBundleFile(), function(err, data) {
Expand All @@ -296,8 +248,7 @@ describe('svg-url-loader', function() {
entry: './test/input/4104B-encoded-unstyled.js'
}
config.module.rules[0].use[0].options.iesafe = true
config.module.rules[0].use[0].options.noquotes = true


webpack(config, function(err) {
expect(err).toBeNull()
fs.readFile(getBundleFile(), function(err, data) {
Expand Down

0 comments on commit b2fe25b

Please sign in to comment.