Skip to content

Commit

Permalink
Fix CSS optimizer with inline style attributes (parcel-bundler#7438)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and bhovhannes committed Dec 23, 2021
1 parent fc4adb3 commit 793acfa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/optimizers/css/package.json
Expand Up @@ -20,7 +20,7 @@
"parcel": "^2.0.1"
},
"dependencies": {
"@parcel/css": "1.0.0-alpha.6",
"@parcel/css": "1.0.0-alpha.7",
"@parcel/plugin": "^2.0.1",
"@parcel/source-map": "^2.0.0",
"@parcel/utils": "^2.0.1",
Expand Down
17 changes: 16 additions & 1 deletion packages/optimizers/css/src/CSSOptimizer.js
Expand Up @@ -3,7 +3,7 @@
import SourceMap from '@parcel/source-map';
import {Optimizer} from '@parcel/plugin';
// $FlowFixMe
import {transform} from '@parcel/css';
import {transform, transformStyleAttribute} from '@parcel/css';
import {blobToBuffer} from '@parcel/utils';
import browserslist from 'browserslist';

Expand All @@ -21,6 +21,21 @@ export default (new Optimizer({

let targets = getTargets(bundle.env.engines.browsers);
let code = await blobToBuffer(prevContents);

// Inline style attributes in HTML need to be parsed differently from full CSS files.
if (bundle.bundleBehavior === 'inline') {
let entry = bundle.getMainEntry();
if (entry?.meta.type === 'attr') {
let contents = transformStyleAttribute({
code,
minify: true,
targets,
});

return {contents};
}
}

let result = transform({
filename: bundle.name,
code,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -2133,10 +2133,10 @@
dependencies:
"@octokit/openapi-types" "^6.2.0"

"@parcel/css@1.0.0-alpha.4":
version "1.0.0-alpha.4"
resolved "https://registry.yarnpkg.com/@parcel/css/-/css-1.0.0-alpha.4.tgz#967520401053f8eb0d5f23ed58b4afbcebc6c9de"
integrity sha512-/wd7WWesAekEexrL7slIkb1gNXX/XYF8bMZUEcEKjDdkfne5SyINLTGbV3WzvsEjzRwgBL5kBET5nX59GJ3JVg==
"@parcel/css@1.0.0-alpha.7":
version "1.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@parcel/css/-/css-1.0.0-alpha.7.tgz#5d8a540fbbce0d63fb959c383313b249e70fb18c"
integrity sha512-uVf1rljfTigmpYI+09U6f4/3Ds3qCvf+NVW4N6PQ2xZuYUkcEjcHqxhSzSgTvOSSwJc+CRcKcho3cQGZ5Z8nbA==
dependencies:
detect-libc "^1.0.3"

Expand Down

0 comments on commit 793acfa

Please sign in to comment.