@defra/docusaurus-theme-govuk 0.0.3-alpha → 0.0.4-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js
CHANGED
|
@@ -91,6 +91,13 @@ module.exports = function themeGovuk(context, options) {
|
|
|
91
91
|
return path.resolve(pkgDir, main);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
// Use MiniCssExtractPlugin for production/server builds, style-loader for dev/client
|
|
95
|
+
let MiniCssExtractPlugin;
|
|
96
|
+
if (!isServer && process.env.NODE_ENV === 'production') {
|
|
97
|
+
MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
98
|
+
if (!config.plugins) config.plugins = [];
|
|
99
|
+
config.plugins.push(new MiniCssExtractPlugin({ filename: 'assets/css/govuk-theme.[contenthash].css' }));
|
|
100
|
+
}
|
|
94
101
|
return {
|
|
95
102
|
// Also resolve webpack loaders from the theme's own node_modules.
|
|
96
103
|
// When consumed via file: (local dev), loaders like style-loader,
|
|
@@ -212,7 +219,9 @@ module.exports = function themeGovuk(context, options) {
|
|
|
212
219
|
{
|
|
213
220
|
test: /\.scss$/,
|
|
214
221
|
use: [
|
|
215
|
-
'
|
|
222
|
+
(!isServer && process.env.NODE_ENV === 'production')
|
|
223
|
+
? require('mini-css-extract-plugin').loader
|
|
224
|
+
: 'style-loader',
|
|
216
225
|
{
|
|
217
226
|
loader: 'css-loader',
|
|
218
227
|
options: {
|
|
@@ -234,10 +243,6 @@ module.exports = function themeGovuk(context, options) {
|
|
|
234
243
|
loader: 'sass-loader',
|
|
235
244
|
options: {
|
|
236
245
|
implementation: require(require.resolve('sass', { paths: [siteDir] })),
|
|
237
|
-
// Override GOV.UK asset path to include the Docusaurus baseUrl.
|
|
238
|
-
// The default '../../assets/' produces URLs without baseUrl,
|
|
239
|
-
// causing 404s when baseUrl is not '/'.
|
|
240
|
-
// Only prepend for SCSS/Sass files — plain CSS can't use Sass variables.
|
|
241
246
|
additionalData: (content, loaderContext) => {
|
|
242
247
|
if (/\.scss$|\.sass$/.test(loaderContext.resourcePath)) {
|
|
243
248
|
return `$govuk-assets-path: '${baseUrl}assets/';\n` + content;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/docusaurus-theme-govuk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-alpha",
|
|
4
4
|
"description": "A Docusaurus theme implementing the GOV.UK Design System for consistent, accessible documentation sites",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=18.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"mini-css-extract-plugin": "^2.10.0"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -43,13 +43,9 @@ export const useIsActive = () => {
|
|
|
43
43
|
|
|
44
44
|
return (href, exact = true) => {
|
|
45
45
|
const target = URI.parse(href, location.pathname);
|
|
46
|
-
const
|
|
47
|
-
// Root path '/' should only match exactly, not as a prefix for all paths
|
|
48
|
-
const pathStart = target.pathname === '' || (target.pathname !== '/' && location.pathname.startsWith(dir));
|
|
49
|
-
const pathMatch = target.pathname === '' || location.pathname === target.pathname;
|
|
46
|
+
const pathMatch = location.pathname === target.pathname;
|
|
50
47
|
const queryMatch = includes(location.query, target.query);
|
|
51
|
-
|
|
52
|
-
return exact ? activeExact : !!(activeExact || (pathStart && queryMatch));
|
|
48
|
+
return pathMatch && queryMatch;
|
|
53
49
|
};
|
|
54
50
|
};
|
|
55
51
|
|