Skip to content

Commit

Permalink
Add bundle-text pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed Nov 6, 2019
1 parent cc36cee commit e1f2a1a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/configs/default/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"bundler": "@parcel/bundler-default",
"transforms": {
"types:*.{ts,tsx}": ["@parcel/transformer-typescript-types"],
"bundle-text:*": ["@parcel/transformer-inline-string", "..."],
"data-url:*": ["@parcel/transformer-inline-string", "..."],
"*.{js,mjs,jsm,jsx,es6,ts,tsx}": [
"@parcel/transformer-babel",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('css', () => {
assert.equal(
css,
`.svg-img {
background-image: url('data:image/svg+xml,%3Csvg%3E%3C%2Fsvg%3E%0A');
background-image: url('data:image/svg+xml,%3Csvg%3E%0A%0A%3C%2Fsvg%3E%0A');
}
`
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import cssText from 'bundle-text:./text.scss';
export default cssText;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$black: #000000;

body {
background-color: $black;
}

.svg-img {
background-image: url('data-url:img.svg');
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1585,12 +1585,29 @@ describe('javascript', function() {
await run(b);
});

it("should inline a bundle's compiled text with `bundle-text`", async () => {
let b = await bundle(
path.join(__dirname, '/integration/bundle-text/index.js')
);

assert.equal(
(await run(b)).default,
`body {
background-color: #000000;
}
.svg-img {
background-image: url("data:image/svg+xml,%3Csvg%3E%0A%0A%3C%2Fsvg%3E%0A");
}`
);
});

it('should inline text content as url-encoded text and mime type with `data-url:*` imports', async () => {
let b = await bundle(path.join(__dirname, '/integration/data-url/text.js'));

assert.equal(
(await run(b)).default,
'data:image/svg+xml,%3Csvg%3E%3C%2Fsvg%3E%0A'
'data:image/svg+xml,%3Csvg%3E%0A%0A%3C%2Fsvg%3E%0A'
);
});

Expand Down

0 comments on commit e1f2a1a

Please sign in to comment.