Skip to content

Commit

Permalink
Updated and improved piral-cli-webpack5
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Dec 26, 2024
1 parent 1b32d52 commit 6a73ca8
Show file tree
Hide file tree
Showing 9 changed files with 1,533 additions and 471 deletions.
49 changes: 24 additions & 25 deletions src/tooling/piral-cli-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,36 @@
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"@types/cheerio": "^0.22.21",
"@types/loader-utils": "^1.1.3",
"@types/mini-css-extract-plugin": "^2.5.1",
"@types/loader-utils": "^2",
"@types/mini-css-extract-plugin": "^2",
"@types/node": "^18",
"@types/terser-webpack-plugin": "^5.2.0",
"@types/yargs": "^17",
"piral-cli": "^1.7.3",
"strip-ansi": "^6.0.0"
"strip-ansi": "^6"
},
"dependencies": {
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@babel/core": "^7",
"@babel/preset-env": "^7",
"@babel/preset-react": "^7",
"ansi-html-community": "0.0.8",
"babel-loader": "^9.1.3",
"cheerio": "^1.0.0",
"css-loader": "^6.11.0",
"css-minimizer-webpack-plugin": "^5.0.1",
"express": "^4.21.2",
"html-entities": "^1.2.0",
"html-webpack-plugin": "^5.6.0",
"loader-utils": "^2.0.4",
"mini-css-extract-plugin": "^2.7.6",
"parcel-codegen-loader": "^1.0.0",
"sass": "^1.63.6",
"sass-loader": "^13.3.2",
"source-map-loader": "^4.0.1",
"style-loader": "^3.3.4",
"systemjs-webpack-interop": "^2.3.7",
"terser-webpack-plugin": "^5.3.10",
"ts-loader": "^9.5.1",
"webpack": "^5.94.0"
"babel-loader": "^9",
"cheerio": "^1",
"css-loader": "^7",
"css-minimizer-webpack-plugin": "^7",
"express": "^4",
"html-entities": "^1",
"html-webpack-plugin": "^5",
"loader-utils": "^2",
"mini-css-extract-plugin": "^2",
"parcel-codegen-loader": "^2",
"sass": "^1.83.0",
"sass-loader": "^16",
"source-map-loader": "^4",
"style-loader": "^4",
"systemjs-webpack-interop": "^2",
"terser-webpack-plugin": "^5",
"ts-loader": "^9",
"webpack": "^5"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, WebpackPluginInstance } from 'webpack';
import type { Compiler, WebpackPluginInstance } from 'webpack';

export class HotModuleServerPlugin implements WebpackPluginInstance {
constructor(private hmrPort: number) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Configuration, Entry } from 'webpack';
import type { CheerioAPI } from 'cheerio';
import type { Configuration, Entry } from 'webpack';

export function isLocal(path: string) {
if (path) {
Expand All @@ -18,15 +19,15 @@ export function isLocal(path: string) {
return false;
}

export function extractParts(content: cheerio.Root) {
export function extractParts(content: CheerioAPI) {
const sheets = content('link[href][rel=stylesheet]')
.filter((_, e: cheerio.TagElement) => isLocal(e.attribs.href))
.filter((_, e) => isLocal(e.attribs.href))
.remove()
.toArray() as Array<cheerio.TagElement>;
.toArray();
const scripts = content('script[src]')
.filter((_, e: cheerio.TagElement) => isLocal(e.attribs.src))
.filter((_, e) => isLocal(e.attribs.src))
.remove()
.toArray() as Array<cheerio.TagElement>;
.toArray();
const files: Array<string> = [];

for (const sheet of sheets) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import { Configuration } from 'webpack';
import type { Configuration } from 'webpack';
import { load } from 'cheerio';
import { readFileSync } from 'fs';
import { join, dirname } from 'path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path';
import { SharedDependency } from 'piral-cli';
import { Configuration } from 'webpack';
import type { SharedDependency } from 'piral-cli';
import type { Configuration } from 'webpack';

export function getVariables(name: string, version: string, env: string): Record<string, string> {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/tooling/piral-cli-webpack5/src/plugins/SheetPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path';
import { Compilation } from 'webpack';
import { Compilation, Compiler } from 'webpack';
import { RawSource } from 'webpack-sources';

export default class SheetPlugin {
Expand All @@ -9,7 +9,7 @@ export default class SheetPlugin {
this.loaderPath = resolve(__dirname, `SheetLoader?cssName=${cssName}&piletName=${piletName}!`);
}

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

entry[this.entryName].import = [this.loaderPath, ...entry[this.entryName].import];
Expand Down
2 changes: 1 addition & 1 deletion src/tooling/piral-cli-webpack5/src/plugins/StylesLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getOptions } from 'loader-utils';

export default function stylesLoader() {
const { cssName, entries } = getOptions(this);
const { cssName, entries } = getOptions(this) as Record<string, string>;
const debug = process.env.NODE_ENV === 'development';
return [
`const u = ${JSON.stringify(cssName)}`,
Expand Down
4 changes: 2 additions & 2 deletions src/tooling/piral-cli-webpack5/src/plugins/StylesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { posix, resolve } from 'path';
import { Compilation } from 'webpack';
import { Compilation, Compiler } from 'webpack';
import { RawSource } from 'webpack-sources';

export default class StylesPlugin {
constructor(private cssName: string, private entryName: string) {}

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

const entries = entry[this.entryName].import.map((e: string) => e.split('\\').join(posix.sep));
Expand Down
Loading

0 comments on commit 6a73ca8

Please sign in to comment.