Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not generating assets URLs #16

Open
sukovec opened this issue Apr 5, 2021 · 2 comments
Open

Not generating assets URLs #16

sukovec opened this issue Apr 5, 2021 · 2 comments

Comments

@sukovec
Copy link

sukovec commented Apr 5, 2021

Hi,

I know this plugin is not developed anymore, written for WP4, but right now it's somewhat compatible with WP5 yet few features stopped working, probably caused by hook name changes (i. e. compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration does not exist anymore). I wasn't able to make a quick fix in code, as I don't understand webpack, html plugin nor this plguin enough to make it work again. Maybe I'll immerse into it one day but I doubt it. Nonetheless I've made quick&dirty workaround for generating link tag in HTML without creating a template like an answer in Issue #8 suggests based on https://github.com/jantimon/html-webpack-plugin#beforeassettaggeneration-hook

Heres the code you can paste directly to webpack.config.js (or anywhere else and include it using require):

class InsertFontCSS {
	constructor(url) { this.url = url; }
	apply(compiler) {
		compiler.hooks.compilation.tap('InsertFontCSS', (compilation) => {
    			HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync('InsertFontCSS',
				(data, cb) => { data.assets.css.push(this.url); cb(null, data) }
			)
		})
	}
}

Than it's enough to use furher in wp configuration:

plugins: [
	new GoogleFontsPlugin({
		fonts: [
			{ family: "Source Sans Pro" },
			{ family: "Roboto" },
			{ family: "Vollkorn" }
		],
		local: true
	}),
	new InsertFontCSS("./fonts.css"),
	new HtmlWebpackPlugin({ "title": "My fonts are working, yay!" }),
]
@PerfectionVR
Copy link

This works for me, although would be nice if the package was being maintained again.

@antony
Copy link
Member

antony commented Sep 27, 2021

We don't use Webpack any more so it won't be maintained. Happy for somebody to take it over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants