next-with-linaria 0.3.1 → 0.4.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
CHANGED
|
@@ -100,6 +100,16 @@ export default function RootLayout({
|
|
|
100
100
|
|
|
101
101
|
This convention is needed because the loader needs to know which files contain global styles and which don't.
|
|
102
102
|
|
|
103
|
+
## Config
|
|
104
|
+
|
|
105
|
+
For details on the config options, see the [Linaria Config](https://github.com/callstack/linaria/blob/master/docs/CONFIGURATION.md).
|
|
106
|
+
|
|
107
|
+
### Plugin specific config
|
|
108
|
+
|
|
109
|
+
`enableInMemoryCache` (default: `true`).
|
|
110
|
+
|
|
111
|
+
If set to `true`, the loader will generate a hash for the file content and store the transformed code in memory and only re-run the transformation if the file has changed. This can increase performance when working with large files. However, hashing the file content, even though it is pretty fast compared to the transformation, can still take some time. If you are experiencing performance or memory issues, you can disable this feature.
|
|
112
|
+
|
|
103
113
|
## Good to know
|
|
104
114
|
|
|
105
115
|
Because webpack 5 caches modules, the virtual CSS Modules need to be cached as well (so at that point the are not really virtual anymore, are they? Anyway...). They are placed in the same directory as where webpack puts its cache files. If the `next-with-linaria` cache is not in sync with the webpack cache anymore, it will cause errors due to missing CSS Modules. If you encounter such an error, you can delete the `.next/cache/webpack` folder and restart the dev server.
|
|
@@ -7,6 +7,7 @@ export declare const regexLinariaModuleCSS: RegExp;
|
|
|
7
7
|
export declare const regexLinariaGlobalCSS: RegExp;
|
|
8
8
|
export declare const regexLinariaCSS: RegExp;
|
|
9
9
|
export type LinariaLoaderOptions = {
|
|
10
|
+
enableInMemoryCache?: boolean;
|
|
10
11
|
moduleStore: VirtualModuleStore;
|
|
11
12
|
preprocessor?: Preprocessor;
|
|
12
13
|
sourceMap?: boolean;
|
|
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.regexLinariaCSS = exports.regexLinariaGlobalCSS = exports.regexLinariaModuleCSS = exports.LINARIA_GLOBAL_EXTENSION = exports.LINARIA_MODULE_EXTENSION = void 0;
|
|
18
18
|
const babel_preset_1 = require("@linaria/babel-preset");
|
|
19
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
19
20
|
const path_1 = __importDefault(require("path"));
|
|
20
21
|
exports.LINARIA_MODULE_EXTENSION = '.linaria.module';
|
|
21
22
|
exports.LINARIA_GLOBAL_EXTENSION = '.linaria.global';
|
|
@@ -29,9 +30,19 @@ function convertSourceMap(value, filename) {
|
|
|
29
30
|
}
|
|
30
31
|
return Object.assign(Object.assign({}, value), { file: (_a = value.file) !== null && _a !== void 0 ? _a : filename, mappings: (_b = value.mappings) !== null && _b !== void 0 ? _b : '', names: (_c = value.names) !== null && _c !== void 0 ? _c : [], sources: (_d = value.sources) !== null && _d !== void 0 ? _d : [], version: (_e = value.version) !== null && _e !== void 0 ? _e : 3 });
|
|
31
32
|
}
|
|
33
|
+
const cache = new Map();
|
|
32
34
|
const transformLoader = function (content, inputSourceMap) {
|
|
35
|
+
const _a = this.getOptions() || {}, { sourceMap = undefined, preprocessor = undefined, moduleStore, enableInMemoryCache = true } = _a, rest = __rest(_a, ["sourceMap", "preprocessor", "moduleStore", "enableInMemoryCache"]);
|
|
36
|
+
let contentHash;
|
|
37
|
+
if (enableInMemoryCache) {
|
|
38
|
+
contentHash = crypto_1.default.createHash('md5').update(content).digest('hex');
|
|
39
|
+
const cacheEntry = cache.get(this.resourcePath);
|
|
40
|
+
if ((cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.hash) === contentHash) {
|
|
41
|
+
this.callback(null, cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.code, cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.sourceMap);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
33
45
|
this.async();
|
|
34
|
-
const _a = this.getOptions() || {}, { sourceMap = undefined, preprocessor = undefined, moduleStore } = _a, rest = __rest(_a, ["sourceMap", "preprocessor", "moduleStore"]);
|
|
35
46
|
const asyncResolve = (token, importer) => {
|
|
36
47
|
const context = path_1.default.isAbsolute(importer)
|
|
37
48
|
? path_1.default.dirname(importer)
|
|
@@ -58,7 +69,7 @@ const transformLoader = function (content, inputSourceMap) {
|
|
|
58
69
|
pluginOptions: rest,
|
|
59
70
|
preprocessor,
|
|
60
71
|
}, asyncResolve).then(async (result) => {
|
|
61
|
-
var _a, _b
|
|
72
|
+
var _a, _b;
|
|
62
73
|
if (result.cssText) {
|
|
63
74
|
let { cssText } = result;
|
|
64
75
|
if (sourceMap) {
|
|
@@ -75,14 +86,29 @@ const transformLoader = function (content, inputSourceMap) {
|
|
|
75
86
|
moduleStore.addModule(fullPathToModule, cssText),
|
|
76
87
|
moduleStore.addModuleDependencies(fullPathToModule, this.getDependencies()),
|
|
77
88
|
]);
|
|
78
|
-
|
|
89
|
+
const code = `${result.code}\n\nrequire("./${cssModuleName}");`;
|
|
90
|
+
if (enableInMemoryCache) {
|
|
91
|
+
cache.set(this.resourcePath, {
|
|
92
|
+
code,
|
|
93
|
+
hash: contentHash,
|
|
94
|
+
sourceMap: result.sourceMap,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
this.callback(null, code, result.sourceMap || undefined);
|
|
79
98
|
}
|
|
80
99
|
catch (err) {
|
|
81
100
|
this.callback(err);
|
|
82
101
|
}
|
|
83
102
|
return;
|
|
84
103
|
}
|
|
85
|
-
|
|
104
|
+
if (enableInMemoryCache) {
|
|
105
|
+
cache.set(this.resourcePath, {
|
|
106
|
+
code: result.code,
|
|
107
|
+
hash: contentHash,
|
|
108
|
+
sourceMap: result.sourceMap,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
this.callback(null, result.code, result.sourceMap || undefined);
|
|
86
112
|
}, (err) => this.callback(err));
|
|
87
113
|
};
|
|
88
114
|
exports.default = transformLoader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformLoader.js","sourceRoot":"","sources":["../../src/loaders/transformLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"transformLoader.js","sourceRoot":"","sources":["../../src/loaders/transformLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAaA,wDAAkD;AAClD,oDAA4B;AAC5B,gDAAwB;AAKX,QAAA,wBAAwB,GAAG,iBAAiB,CAAC;AAC7C,QAAA,wBAAwB,GAAG,iBAAiB,CAAC;AAE7C,QAAA,qBAAqB,GAAG,yBAAyB,CAAC;AAClD,QAAA,qBAAqB,GAAG,yBAAyB,CAAC;AAClD,QAAA,eAAe,GAAG,kCAAkC,CAAC;AAmBlE,SAAS,gBAAgB,CACvB,KAAgC,EAChC,QAAgB;;IAEhB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,EAAE;QACvC,OAAO,SAAS,CAAC;KAClB;IAED,uCACK,KAAK,KACR,IAAI,EAAE,MAAA,KAAK,CAAC,IAAI,mCAAI,QAAQ,EAC5B,QAAQ,EAAE,MAAA,KAAK,CAAC,QAAQ,mCAAI,EAAE,EAC9B,KAAK,EAAE,MAAA,KAAK,CAAC,KAAK,mCAAI,EAAE,EACxB,OAAO,EAAE,MAAA,KAAK,CAAC,OAAO,mCAAI,EAAE,EAC5B,OAAO,EAAE,MAAA,KAAK,CAAC,OAAO,mCAAI,CAAC,IAC3B;AACJ,CAAC;AAKD,MAAM,KAAK,GAAG,IAAI,GAAG,EAOlB,CAAC;AAEJ,MAAM,eAAe,GAAe,UAAU,OAAO,EAAE,cAAc;IACnE,MAAM,KAMF,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EANrB,EACJ,SAAS,GAAG,SAAS,EACrB,YAAY,GAAG,SAAS,EACxB,WAAW,EACX,mBAAmB,GAAG,IAAI,OAED,EADtB,IAAI,cALH,mEAML,CAA0B,CAAC;IAE5B,IAAI,WAAW,CAAC;IAChB,IAAI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CHANGED
|
@@ -108,5 +108,13 @@ export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig):
|
|
|
108
108
|
} | undefined;
|
|
109
109
|
} | undefined;
|
|
110
110
|
output?: "standalone" | undefined;
|
|
111
|
+
transpilePackages?: string[] | undefined;
|
|
112
|
+
skipMiddlewareUrlNormalize?: boolean | undefined;
|
|
113
|
+
skipTrailingSlashRedirect?: boolean | undefined;
|
|
114
|
+
modularizeImports?: Record<string, {
|
|
115
|
+
transform: string;
|
|
116
|
+
preventFullImport?: boolean | undefined;
|
|
117
|
+
skipDefaultConversion?: boolean | undefined;
|
|
118
|
+
}> | undefined;
|
|
111
119
|
experimental?: NextServer.ExperimentalConfig | undefined;
|
|
112
120
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-with-linaria",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Linaria support for Next.js 13 app directory feature",
|
|
5
5
|
"main": "lib/webpackConfig.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,28 +13,28 @@
|
|
|
13
13
|
},
|
|
14
14
|
"packageManager": "pnpm@7.14.0",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@linaria/babel-preset": "4.
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
18
|
-
"@typescript-eslint/parser": "5.
|
|
19
|
-
"eslint": "8.
|
|
20
|
-
"eslint-config-prettier": "8.
|
|
16
|
+
"@linaria/babel-preset": "4.4.1",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "5.51.0",
|
|
18
|
+
"@typescript-eslint/parser": "5.51.0",
|
|
19
|
+
"eslint": "8.33.0",
|
|
20
|
+
"eslint-config-prettier": "8.6.0",
|
|
21
21
|
"eslint-plugin-prettier": "4.2.1",
|
|
22
|
-
"eslint-plugin-simple-import-sort": "
|
|
22
|
+
"eslint-plugin-simple-import-sort": "10.0.0",
|
|
23
23
|
"eslint-plugin-typescript-sort-keys": "2.1.0",
|
|
24
24
|
"eslint-plugin-unused-imports": "2.0.0",
|
|
25
25
|
"is-ci": "3.0.1",
|
|
26
|
-
"lint-staged": "13.
|
|
27
|
-
"next": "13.
|
|
28
|
-
"prettier": "2.
|
|
26
|
+
"lint-staged": "13.1.1",
|
|
27
|
+
"next": "13.1.6",
|
|
28
|
+
"prettier": "2.8.4",
|
|
29
29
|
"simple-git-hooks": "2.8.1",
|
|
30
|
-
"typescript": "4.9.
|
|
30
|
+
"typescript": "4.9.5",
|
|
31
31
|
"webpack": "5.75.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@linaria/babel-preset": "4.x"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"file-system-cache": "2.0.
|
|
37
|
+
"file-system-cache": "2.0.2"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"lib"
|