Skip to content

Commit

Permalink
feat: add experimental syntax to include compiled CSS into style tag
Browse files Browse the repository at this point in the history
webdiscus committed Apr 5, 2024
1 parent bc00a04 commit 74ef323
Showing 4 changed files with 1,550 additions and 1,617 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change log

## 5.2.0 (2024-04-06)

- feat: add experimental (undocumented) syntax to include (using `?include` query) compiled CSS directly into style tag to allow keep tag attributes
```pug
style(scope='some')=require('./component.scss?include')
```
will be generate
```html
<style scope="some">
... CSS ...
</style>
```
## 5.1.0 (2024-03-21)
- feat: app the `pretty` and `prettyOptions` options to format the generated HTML
3,104 changes: 1,527 additions & 1,577 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pug-plugin",
"version": "5.1.0",
"version": "5.2.0",
"description": "Pug plugin for webpack handles a template as an entry point, extracts CSS and JS from their sources referenced in Pug.",
"keywords": [
"html",
@@ -67,34 +67,34 @@
},
"dependencies": {
"ansis": "2.0.3",
"html-bundler-webpack-plugin": "3.7.0",
"html-bundler-webpack-plugin": "3.8.0",
"js-beautify": "^1.15.1",
"pug": "3.0.2"
},
"devDependencies": {
"@babel/core": "7.24.0",
"@babel/preset-env": "7.24.0",
"@babel/core": "7.24.4",
"@babel/preset-env": "7.24.4",
"@test-fixtures/js": "0.0.2",
"@test-fixtures/lorem": "0.0.2",
"@test-fixtures/scss": "0.0.7",
"@types/jest": "^29.5.12",
"css-loader": "^6.10.0",
"cssnano": "^6.1.0",
"css-loader": "^6.11.0",
"cssnano": "^6.1.2",
"jest": "^29.7.0",
"mini-css-extract-plugin": "^2.8.1",
"normalize.css": "^8.0.1",
"postcss-loader": "^8.1.1",
"prettier": "^3.2.5",
"@test/pug-plugin": "file:./",
"responsive-loader": "^3.1.2",
"sass": "1.71.1",
"sass": "1.74.1",
"sass-loader": "^14.1.1",
"sharp": "0.32.6",
"svgo-loader": "^4.0.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"webpack": "5.90.3",
"webpack": "5.91.0",
"webpack-cli": "5.1.4",
"webpack-dev-server": "^5.0.2",
"webpack-dev-server": "^5.0.4",
"webpack-merge": "^5.10.0"
}
}
32 changes: 1 addition & 31 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -7,31 +7,6 @@ Config.init(path.join(__dirname, './config.js'));
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
const formatHtml = require('js-beautify').html;

/**
* Resolve undefined|true|false|''|'auto' value depend on current Webpack mode dev/prod.
*
* @param {boolean|string|undefined} value The value one of the values: true, false, 'auto'.
* @param {boolean} autoDevValue Returns the autoValue in dev mode when value is 'auto'.
* @param {boolean} autoProdValue Returns the autoValue in prod mode when value is 'auto'.
* @param {boolean|string} defaultValue Returns default value when value is undefined.
* @param {boolean} isProd Is production mode.
* @return {boolean}
*/
const toBool = (value, { autoDevValue, autoProdValue, defaultValue, isProd }) => {
if (value == null) value = defaultValue;
// note: if a parameter is defined without a value or value is empty, then the value is true
if (value === '' || value === 'true') return true;
if (value === 'false') return false;
if (value === true || value === false) return value;

if (value === 'auto') {
if (!isProd && autoDevValue != null) return autoDevValue;
if (isProd && autoProdValue != null) return autoProdValue;
}

return false;
};

/**
* @typedef {PluginOptions} HtmlBundlerPluginOptions
*/
@@ -109,16 +84,11 @@ class PugPlugin extends HtmlBundlerPlugin {
isPretty = true;
prettyOption = { ...defaultPrettyOptions, ...userPrettyOptions };
} else {
isPretty = toBool(pretty, {
defaultValue: false,
autoDevValue: true,
isProd: PugPlugin.option.productionMode,
});
isPretty = PugPlugin.option.toBool(pretty, false, false);
prettyOption = defaultPrettyOptions;
}

if (isPretty) {
//console.log({ prettyOption });
PugPlugin.option.addProcess('postprocess', (content) => formatHtml(content, prettyOption));
}
}

0 comments on commit 74ef323

Please sign in to comment.