next-yak 0.0.2 → 0.0.4
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 +7 -6
- package/loaders/cssloader.cjs +3 -4
- package/loaders/tsloader.cjs +3 -4
- package/loaders/withYak.cjs +5 -0
- package/package.json +3 -1
- package/loaders/lib/loadConfigOnce.cjs +0 -17
package/README.md
CHANGED
|
@@ -98,15 +98,15 @@ next-yak provide class name helpers. This allows using [tailwind](https://tailwi
|
|
|
98
98
|
```tsx
|
|
99
99
|
import { styled, css, atoms } from "next-yak";
|
|
100
100
|
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const Button = styled.button<{ $primary?: boolean }>`
|
|
102
|
+
${atoms("text-teal-600", "text-base", "rounded-md")}
|
|
103
|
+
${props => props.$primary && atoms("shadow-md")}
|
|
104
104
|
`;
|
|
105
105
|
|
|
106
106
|
const App = () => (
|
|
107
|
-
<
|
|
107
|
+
<Button primary>
|
|
108
108
|
Hello World
|
|
109
|
-
</
|
|
109
|
+
</Button>
|
|
110
110
|
);
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -115,7 +115,8 @@ const App = () => (
|
|
|
115
115
|
This is a proof of concept. There are a lot of things that need to be done before this can be used in production:
|
|
116
116
|
|
|
117
117
|
- [ ] improve js parsing - right now it not reusing babel..
|
|
118
|
-
- [ ]
|
|
118
|
+
- [ ] sourcemaps
|
|
119
|
+
- [ ] replace config apporach with a solution similar to vanilla-extracts `.styles.ts` files
|
|
119
120
|
|
|
120
121
|
## Prior art
|
|
121
122
|
|
package/loaders/cssloader.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const babel = require("@babel/core");
|
|
3
3
|
const quasiClassifier = require("./lib/quasiClassifier.cjs");
|
|
4
4
|
const replaceQuasiExpressionTokens = require("./lib/replaceQuasiExpressionTokens.cjs");
|
|
5
|
-
const loadConfigOnce = require("./lib/loadConfigOnce.cjs");
|
|
6
5
|
const murmurhash2_32_gc = require("./lib/hash.cjs");
|
|
7
6
|
const { relative, resolve } = require("path");
|
|
8
7
|
|
|
@@ -15,9 +14,9 @@ module.exports = async function cssLoader(source) {
|
|
|
15
14
|
// Config for replacing tokens in css template literals
|
|
16
15
|
// can be based on a typescript file
|
|
17
16
|
const options = this.getOptions();
|
|
18
|
-
const config = options.configPath ? await
|
|
19
|
-
|
|
20
|
-
) : {};
|
|
17
|
+
const config = options.configPath ? await this.importModule(resolve(this.rootContext, options.configPath), {
|
|
18
|
+
layer: "yak-importModule",
|
|
19
|
+
}) : {};
|
|
21
20
|
const replaces = config.replaces || {};
|
|
22
21
|
|
|
23
22
|
// parse source with babel
|
package/loaders/tsloader.cjs
CHANGED
|
@@ -3,7 +3,6 @@ const path = require("path");
|
|
|
3
3
|
const babel = require("@babel/core");
|
|
4
4
|
const quasiClassifier = require("./lib/quasiClassifier.cjs");
|
|
5
5
|
const replaceQuasiExpressionTokens = require("./lib/replaceQuasiExpressionTokens.cjs");
|
|
6
|
-
const loadConfigOnce = require("./lib/loadConfigOnce.cjs");
|
|
7
6
|
const murmurhash2_32_gc = require("./lib/hash.cjs");
|
|
8
7
|
const { relative, resolve } = require("path");
|
|
9
8
|
|
|
@@ -22,9 +21,9 @@ module.exports = async function tsloader(source) {
|
|
|
22
21
|
// Config for replacing tokens in css template literals
|
|
23
22
|
// can be based on a typescript file
|
|
24
23
|
const options = this.getOptions();
|
|
25
|
-
const config = options.configPath ? await
|
|
26
|
-
|
|
27
|
-
) : {};
|
|
24
|
+
const config = options.configPath ? await this.importModule(resolve(this.rootContext, options.configPath), {
|
|
25
|
+
layer: "yak-importModule",
|
|
26
|
+
}) : {};
|
|
28
27
|
const replaces = config.replaces || {};
|
|
29
28
|
|
|
30
29
|
/** @type {string | null} */
|
package/loaders/withYak.cjs
CHANGED
|
@@ -17,6 +17,11 @@ const addYak = (yakOptions, nextConfig) => {
|
|
|
17
17
|
test: /\.tsx?$/,
|
|
18
18
|
loader: require.resolve("./tsloader.cjs"),
|
|
19
19
|
options: yakOptions,
|
|
20
|
+
issuerLayer: {
|
|
21
|
+
// prevent recursions when calling this.importModule
|
|
22
|
+
// in the tsloader
|
|
23
|
+
not: ["yak-importModule"],
|
|
24
|
+
},
|
|
20
25
|
});
|
|
21
26
|
webpackConfig.module.rules.push({
|
|
22
27
|
test: /\.yak\.module\.css$/,
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @type {Promise<{ replaces?: Record<string, Record<string, string>> }>}
|
|
5
|
-
*/
|
|
6
|
-
let cache;
|
|
7
|
-
module.exports = function loadConfigOnce(loader) {
|
|
8
|
-
const config = cache || loader().catch((e) => {
|
|
9
|
-
console.error("Failed to load yak config:", e);
|
|
10
|
-
return {};
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
if (!cache) {
|
|
14
|
-
cache = config;
|
|
15
|
-
}
|
|
16
|
-
return config;
|
|
17
|
-
};
|