Skip to content

Commit fddfdb9

Browse files
olizilladevongovett
authored andcommitted
Fix #698 - safe cssnano transforms by default (#707)
1 parent fc641fa commit fddfdb9

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/transforms/postcss.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ async function getConfig(asset) {
5151

5252
if (asset.options.minify) {
5353
config.plugins.push(
54-
cssnano((await asset.getConfig(['cssnano.config.js'])) || {})
54+
cssnano(
55+
(await asset.getConfig(['cssnano.config.js'])) || {
56+
// Only enable safe css transforms by default.
57+
// See: https://github.com/parcel-bundler/parcel/issues/698
58+
// Note: Remove when upgrading cssnano to v4
59+
// See: https://github.com/ben-eb/cssnano/releases/tag/v4.0.0-rc.0
60+
safe: true
61+
}
62+
)
5563
);
5664
}
5765

test/css.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,48 @@ describe('css', function() {
146146
);
147147
});
148148

149+
it('should support linking to assets with url() from CSS in production', async function() {
150+
let b = await bundle(__dirname + '/integration/css-url/index.js', {
151+
production: true
152+
});
153+
154+
assertBundleTree(b, {
155+
name: 'index.js',
156+
assets: ['index.js', 'index.css'],
157+
childBundles: [
158+
{
159+
name: 'index.css',
160+
assets: ['index.css'],
161+
childBundles: []
162+
},
163+
{
164+
type: 'woff2',
165+
assets: ['test.woff2'],
166+
childBundles: []
167+
}
168+
]
169+
});
170+
171+
let output = run(b);
172+
assert.equal(typeof output, 'function');
173+
assert.equal(output(), 2);
174+
175+
let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
176+
assert(/url\([0-9a-f]+\.woff2\)/.test(css), 'woff ext found in css');
177+
assert(css.includes('url(http://google.com)'), 'url() found');
178+
assert(css.includes('.index'), '.index found');
179+
assert(css.includes('url("data:image/gif;base64,quotes")'));
180+
assert(css.includes('.quotes'));
181+
assert(css.includes('url(data:image/gif;base64,no-quote)'));
182+
assert(css.includes('.no-quote'));
183+
184+
assert(
185+
fs.existsSync(
186+
__dirname + '/dist/' + css.match(/url\(([0-9a-f]+\.woff2)\)/)[1]
187+
)
188+
);
189+
});
190+
149191
it('should support transforming with postcss', async function() {
150192
let b = await bundle(__dirname + '/integration/postcss/index.js');
151193

0 commit comments

Comments
 (0)