@pantoken/webpack 0.1.0

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/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @pantoken/webpack
2
+
3
+ A Webpack 5 plugin that emits the Instructure token stylesheet as a build asset (default
4
+ `pantoken.css`), so you can link it from your HTML without importing the large package into a bundle.
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm i -D @pantoken/webpack
10
+ ```
11
+
12
+ Also available as `pantoken/webpack`.
13
+
14
+ ## Usage
15
+
16
+ ```js
17
+ // webpack.config.js
18
+ import { PantokenWebpackPlugin } from "@pantoken/webpack";
19
+
20
+ export default {
21
+ plugins: [new PantokenWebpackPlugin()],
22
+ };
23
+ ```
24
+
25
+ This emits `pantoken.css` into the output, ready to link from your HTML. Override the name with
26
+ `new PantokenWebpackPlugin({ filename: "tokens.css" })`. `webpack` is an optional peer dependency.
27
+
28
+ ## API
29
+
30
+ - **`PantokenWebpackPlugin`** — the plugin class. Construct it with an optional `{ filename }` and add
31
+ it to `plugins`. Also the default export.
32
+ - **`PantokenWebpackOptions`** — options type; `filename` sets the emitted asset name.
33
+
34
+ ## Related
35
+
36
+ - Wraps `@pantoken/css`, which supplies the stylesheet this plugin emits.
37
+
38
+ ## License
39
+
40
+ MIT
@@ -0,0 +1,58 @@
1
+ //#region src/index.d.ts
2
+ /** The minimal Webpack compiler surface this plugin uses (avoids a hard dependency on webpack). */
3
+ interface CompilerLike {
4
+ webpack: {
5
+ sources: {
6
+ RawSource: new (source: string) => unknown;
7
+ };
8
+ };
9
+ hooks: {
10
+ thisCompilation: {
11
+ tap: (name: string, fn: (compilation: CompilationLike) => void) => void;
12
+ };
13
+ };
14
+ }
15
+ interface CompilationLike {
16
+ hooks: {
17
+ processAssets: {
18
+ tap: (options: {
19
+ name: string;
20
+ stage?: number;
21
+ }, fn: () => void) => void;
22
+ };
23
+ };
24
+ emitAsset: (name: string, source: unknown) => void;
25
+ }
26
+ /** Options for {@link PantokenWebpackPlugin}. */
27
+ interface PantokenWebpackOptions {
28
+ /** The emitted asset filename (default `"pantoken.css"`). */
29
+ filename?: string;
30
+ }
31
+ /**
32
+ * Webpack plugin that emits the pantoken stylesheet as an output asset.
33
+ *
34
+ * @example Emit pantoken.css from your webpack.config.js
35
+ * ```js
36
+ * import { PantokenWebpackPlugin } from "@pantoken/webpack";
37
+ *
38
+ * export default {
39
+ * plugins: [new PantokenWebpackPlugin()],
40
+ * };
41
+ * ```
42
+ *
43
+ * @example Rename the emitted asset
44
+ * ```js
45
+ * import { PantokenWebpackPlugin } from "@pantoken/webpack";
46
+ *
47
+ * export default {
48
+ * plugins: [new PantokenWebpackPlugin({ filename: "tokens.css" })],
49
+ * };
50
+ * ```
51
+ */
52
+ declare class PantokenWebpackPlugin {
53
+ private readonly filename;
54
+ constructor(options?: PantokenWebpackOptions);
55
+ apply(compiler: CompilerLike): void;
56
+ }
57
+ //#endregion
58
+ export { PantokenWebpackOptions, PantokenWebpackPlugin, PantokenWebpackPlugin as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,47 @@
1
+ import { css } from "@pantoken/css";
2
+ //#region src/index.ts
3
+ /**
4
+ * `@pantoken/webpack` — a Webpack plugin that emits the Instructure token stylesheet as a build
5
+ * asset (default `pantoken.css`), so you can reference it from your HTML without importing the large
6
+ * package into a bundle.
7
+ *
8
+ * @module
9
+ * @experimental
10
+ */
11
+ /**
12
+ * Webpack plugin that emits the pantoken stylesheet as an output asset.
13
+ *
14
+ * @example Emit pantoken.css from your webpack.config.js
15
+ * ```js
16
+ * import { PantokenWebpackPlugin } from "@pantoken/webpack";
17
+ *
18
+ * export default {
19
+ * plugins: [new PantokenWebpackPlugin()],
20
+ * };
21
+ * ```
22
+ *
23
+ * @example Rename the emitted asset
24
+ * ```js
25
+ * import { PantokenWebpackPlugin } from "@pantoken/webpack";
26
+ *
27
+ * export default {
28
+ * plugins: [new PantokenWebpackPlugin({ filename: "tokens.css" })],
29
+ * };
30
+ * ```
31
+ */
32
+ var PantokenWebpackPlugin = class {
33
+ filename;
34
+ constructor(options = {}) {
35
+ this.filename = options.filename ?? "pantoken.css";
36
+ }
37
+ apply(compiler) {
38
+ const { RawSource } = compiler.webpack.sources;
39
+ compiler.hooks.thisCompilation.tap("@pantoken/webpack", (compilation) => {
40
+ compilation.hooks.processAssets.tap({ name: "@pantoken/webpack" }, () => {
41
+ compilation.emitAsset(this.filename, new RawSource(css));
42
+ });
43
+ });
44
+ }
45
+ };
46
+ //#endregion
47
+ export { PantokenWebpackPlugin, PantokenWebpackPlugin as default };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@pantoken/webpack",
3
+ "version": "0.1.0",
4
+ "description": "Webpack plugin for pantoken: emits the token stylesheet as a build asset.",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "exports": {
11
+ ".": "./dist/index.mjs",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "dependencies": {
18
+ "@pantoken/css": "0.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^24.13.3",
22
+ "typescript": "^6.0.3",
23
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
24
+ "vite-plus": "0.2.4"
25
+ },
26
+ "peerDependencies": {
27
+ "webpack": ">=5"
28
+ },
29
+ "peerDependenciesMeta": {
30
+ "webpack": {
31
+ "optional": true
32
+ }
33
+ },
34
+ "pantoken": {
35
+ "key": "webpack",
36
+ "kind": "subpath"
37
+ },
38
+ "scripts": {
39
+ "build": "vp pack",
40
+ "dev": "vp pack --watch",
41
+ "test": "vp test",
42
+ "check": "vp check"
43
+ }
44
+ }