Skip to content

Commit d8b0173

Browse files
Jolyn Denninginternettrans
andauthored
ESM webpack plugin, package.json exports, support no css files (#28)
* ESM webpack plugin, package.json exports, support no css files * Try to fix build --------- Co-authored-by: Jolyn Denning <[email protected]>
1 parent ba54dfd commit d8b0173

File tree

5 files changed

+430
-25
lines changed

5 files changed

+430
-25
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These are supported funding model platforms
22

3-
github: ["joeldenning"]
3+
github: ["jolyndenning"]
44
patreon: singlespa
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username

ExposeRuntimeCssAssetsPlugin.cjs renamed to ExposeRuntimeCssAssetsPlugin.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
const webpack = require("webpack");
2-
const RuntimeModule = require("webpack/lib/RuntimeModule");
3-
const Template = require("webpack/lib/Template");
4-
const { RuntimeGlobals } = require("webpack");
5-
const { MODULE_TYPE } = require("mini-css-extract-plugin/dist/utils");
1+
import webpack from "webpack/lib/index.js";
2+
import RuntimeModule from "webpack/lib/RuntimeModule.js";
3+
import RuntimeGlobals from "webpack/lib/RuntimeGlobals.js";
4+
import Template from "webpack/lib/Template.js";
5+
import { MODULE_TYPE } from "mini-css-extract-plugin/dist/utils.js";
66

77
/** @typedef {import("webpack").Compiler} Compiler */
88
const pluginName = "SingleSpaExposeRuntimeCssAssetsPlugin";
99

1010
class ExposedCssRuntimeModule extends RuntimeModule {
11-
constructor() {
11+
constructor(foundCssModule) {
1212
super("exposed-css-runtime", 10);
13+
this.foundCssModule = foundCssModule;
1314
}
1415
generate() {
1516
return Template.asString(
16-
`${RuntimeGlobals.require}.cssAssets = ${JSON.stringify([
17-
this.chunk.id,
18-
])};`,
17+
`${RuntimeGlobals.require}.cssAssets = ${JSON.stringify(
18+
[this.foundCssModule && this.chunk.id].filter(Boolean),
19+
)};`,
1920
);
2021
}
2122
}
2223

23-
module.exports = class ExposeRuntimeCssAssetsPlugin {
24+
export default class ExposeRuntimeCssAssetsPlugin {
2425
constructor(options) {
2526
this.options = options;
2627
}
@@ -107,14 +108,15 @@ module.exports = class ExposeRuntimeCssAssetsPlugin {
107108
true,
108109
),
109110
);
110-
compilation.addRuntimeModule(
111-
chunk,
112-
new ExposedCssRuntimeModule(),
113-
);
114111
}
112+
113+
compilation.addRuntimeModule(
114+
chunk,
115+
new ExposedCssRuntimeModule(foundCssModule),
116+
);
115117
}
116118
});
117119
});
118120
});
119121
}
120-
};
122+
}

package.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
"version": "3.0.1",
44
"description": "Lifecycle helpers for loading CSS",
55
"type": "module",
6-
"main": "lib/esm/single-spa-css.min.js",
7-
"types": "lib/esm/single-spa-css.d.ts",
6+
"exports": {
7+
".": {
8+
"import": "./lib/esm/single-spa-css.min.js",
9+
"require": "./lib/umd/single-spa-css",
10+
"types": "./lib/esm/single-spa-css.d.ts"
11+
},
12+
"./ExposeRuntimeCssAssetsPlugin": "./ExposeRuntimeCssAssetsPlugin.js"
13+
},
814
"scripts": {
915
"test": "jest",
1016
"clean": "rimraf lib",
@@ -24,7 +30,7 @@
2430
"type": "git",
2531
"url": "git+https://github.com/single-spa/single-spa-css.git"
2632
},
27-
"author": "Joel Denning",
33+
"author": "Jolyn Denning",
2834
"license": "MIT",
2935
"bugs": {
3036
"url": "https://github.com/single-spa/single-spa-css/issues"
@@ -34,6 +40,8 @@
3440
"@babel/core": "^7.12.10",
3541
"@babel/preset-env": "^7.12.11",
3642
"@babel/preset-typescript": "^7.12.7",
43+
"@eslint/eslintrc": "^3.3.1",
44+
"@eslint/js": "^9.26.0",
3745
"@rollup/plugin-typescript": "^12.1.2",
3846
"@testing-library/dom": "^10.4.0",
3947
"@testing-library/jest-dom": "^6.6.3",
@@ -59,5 +67,9 @@
5967
"dependencies": {
6068
"@types/webpack-env": "^1.16.0"
6169
},
62-
"packageManager": "[email protected]"
70+
"peerDependencies": {
71+
"mini-css-extract-plugin": "*",
72+
"webpack": "*"
73+
},
74+
"packageManager": "[email protected]"
6375
}

0 commit comments

Comments
 (0)