Skip to content

Commit

Permalink
Removed dependency to sheet plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Mar 15, 2022
1 parent 5417983 commit 73338c0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Piral Changelog

## 0.14.19 (tbd)

- Removed dependency to `webpack-inject-plugin` in `piral-cli-webpack5`

## 0.14.18 (March 15, 2022)

- Fixed issue with `v1` pilets not loading additional chunks
Expand Down
3 changes: 1 addition & 2 deletions src/tooling/piral-cli-webpack5/package.json
Expand Up @@ -74,7 +74,6 @@
"systemjs-webpack-interop": "^2.3.7",
"terser-webpack-plugin": "^5.0.0",
"ts-loader": "^8.0.6",
"webpack": "^5.1.3",
"webpack-inject-plugin": "^1.5.5"
"webpack": "^5.1.3"
}
}
16 changes: 16 additions & 0 deletions src/tooling/piral-cli-webpack5/src/plugins/SheetLoader.ts
@@ -0,0 +1,16 @@
import { getOptions } from 'loader-utils';

export default function sheetLoader() {
const { cssName, piletName } = getOptions(this);
const debug = process.env.NODE_ENV === 'development';
return [
`var d=document`,
`var u=__webpack_public_path__+${JSON.stringify(cssName)}`,
`var e=d.createElement("link")`,
`e.setAttribute('data-origin', ${JSON.stringify(piletName)})`,
`e.type="text/css"`,
`e.rel="stylesheet"`,
`e.href=${debug ? 'u+"?_="+Math.random()' : 'u'}`,
`d.head.appendChild(e)`,
].join(';');
}
30 changes: 8 additions & 22 deletions src/tooling/piral-cli-webpack5/src/plugins/SheetPlugin.ts
@@ -1,32 +1,18 @@
import InjectPlugin from 'webpack-inject-plugin';
import { resolve } from 'path';
import { Compilation } from 'webpack';
import { RawSource } from 'webpack-sources';

function sheetLoader(cssName: string, name: string) {
return () => {
const debug = process.env.NODE_ENV === 'development';
return [
`var d=document`,
`var u=__webpack_public_path__+${JSON.stringify(cssName)}`,
`var e=d.createElement("link")`,
`e.setAttribute('data-origin', ${JSON.stringify(name)})`,
`e.type="text/css"`,
`e.rel="stylesheet"`,
`e.href=${debug ? 'u+"?_="+Math.random()' : 'u'}`,
`d.head.appendChild(e)`,
].join(';');
};
}
export default class SheetPlugin {
private loaderPath: string;

export default class SheetPlugin extends InjectPlugin {
constructor(private cssName: string, name: string, entryName: string) {
super(sheetLoader(cssName, name), {
entryName,
});
constructor(private cssName: string, piletName: string, private entryName: string) {
this.loaderPath = resolve(__dirname, `SheetLoader?cssName=${cssName}&piletName=${piletName}!`);
}

apply(compiler) {
super.apply(compiler);
const { entry } = compiler.options;

entry[this.entryName].import = [this.loaderPath, ...entry[this.entryName].import];

compiler.hooks.compilation.tap('SheetPlugin', (compilation: Compilation) => {
if (!compilation.compiler.parentCompilation) {
Expand Down

0 comments on commit 73338c0

Please sign in to comment.