├── package.json ├── README.md └── plugin.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cogear-plugin-base-url", 3 | "description": "Cogear.JS base URL plugin.", 4 | "version": "1.0.0", 5 | "author": "Pacharapol Withayasakpunt", 6 | "homepage": "https://github.com/patarapolw/cogear-plugin-base-url", 7 | "main": "./plugin.js" 8 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Base URL plugin for Cogear.JS 2 | 3 | Allow base URL to be other than "/". Useful of GitHub Page, where base URL is actually ``. Only update for CSS and JavaScript chucks. For other kinds of links, please edit the link in the theme to `cogear.baseUrl`. 4 | 5 | `config.yaml` 6 | 7 | ```yaml 8 | ... 9 | baseUrl: // 10 | ... 11 | ``` 12 | -------------------------------------------------------------------------------- /plugin.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const fs = require("fs"); 3 | const webpack = require("webpack"); 4 | 5 | const BASE_URL = cogear.config.baseUrl || "/"; 6 | 7 | module.exports = { 8 | apply() { 9 | cogear.on("webpack.config", (webpackConfig) => { 10 | cogear.baseUrl = webpackConfig.mode === "production" ? BASE_URL : "/"; 11 | }), 12 | cogear.on("build.page.writeAfter", ([page, html]) => { 13 | html = html.replace(/(