next-with-linaria 0.8.0 → 1.0.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.
Files changed (107) hide show
  1. package/README.md +57 -20
  2. package/lib/{webpackConfig.d.ts → add-turbopack-config.d.ts} +14 -18
  3. package/lib/add-turbopack-config.js +37 -0
  4. package/lib/add-turbopack-config.js.map +1 -0
  5. package/lib/{rspack-config.d.ts → add-webpack-config.d.ts} +4 -3
  6. package/lib/{rspack-config.js → add-webpack-config.js} +20 -37
  7. package/lib/add-webpack-config.js.map +1 -0
  8. package/lib/loaders/consts.d.ts +6 -0
  9. package/lib/loaders/consts.js +10 -0
  10. package/lib/loaders/consts.js.map +1 -0
  11. package/lib/loaders/turbopack-transform-loader.d.ts +5 -0
  12. package/lib/loaders/turbopack-transform-loader.js +72 -0
  13. package/lib/loaders/turbopack-transform-loader.js.map +1 -0
  14. package/lib/loaders/webpack-output-css-loader.d.ts +4 -0
  15. package/lib/loaders/webpack-output-css-loader.js +14 -0
  16. package/lib/loaders/webpack-output-css-loader.js.map +1 -0
  17. package/lib/loaders/webpack-transform-loader.d.ts +12 -0
  18. package/lib/loaders/webpack-transform-loader.js +89 -0
  19. package/lib/loaders/webpack-transform-loader.js.map +1 -0
  20. package/lib/types.d.ts +8 -0
  21. package/lib/{moduleStore.js → types.js} +1 -2
  22. package/lib/types.js.map +1 -0
  23. package/lib/utils/fast-check.d.ts +1 -0
  24. package/lib/utils/fast-check.js +17 -0
  25. package/lib/utils/fast-check.js.map +1 -0
  26. package/lib/utils/insert-import.d.ts +1 -0
  27. package/lib/utils/insert-import.js +22 -0
  28. package/lib/utils/insert-import.js.map +1 -0
  29. package/lib/utils/source-map.d.ts +7 -0
  30. package/lib/utils/source-map.js +11 -0
  31. package/lib/utils/source-map.js.map +1 -0
  32. package/lib/{utils.js → utils/webpack-utils.js} +1 -1
  33. package/lib/utils/webpack-utils.js.map +1 -0
  34. package/lib/with-linaria.d.ts +125 -19
  35. package/lib/with-linaria.js +9 -92
  36. package/lib/with-linaria.js.map +1 -1
  37. package/package.json +3 -6
  38. package/lib/VirtualModuleStore.d.ts +0 -13
  39. package/lib/VirtualModuleStore.js +0 -61
  40. package/lib/VirtualModuleStore.js.map +0 -1
  41. package/lib/examples/logger-examples.d.ts +0 -3
  42. package/lib/examples/logger-examples.js +0 -47
  43. package/lib/examples/logger-examples.js.map +0 -1
  44. package/lib/loaders/output-css-loader-rspack.d.ts +0 -8
  45. package/lib/loaders/output-css-loader-rspack.js +0 -26
  46. package/lib/loaders/output-css-loader-rspack.js.map +0 -1
  47. package/lib/loaders/output-css-loader.d.ts +0 -8
  48. package/lib/loaders/output-css-loader.js +0 -26
  49. package/lib/loaders/output-css-loader.js.map +0 -1
  50. package/lib/loaders/outputCssLoader.d.ts +0 -8
  51. package/lib/loaders/outputCssLoader.js +0 -24
  52. package/lib/loaders/outputCssLoader.js.map +0 -1
  53. package/lib/loaders/tranform-loader-rspack.d.ts +0 -17
  54. package/lib/loaders/tranform-loader-rspack.js +0 -98
  55. package/lib/loaders/tranform-loader-rspack.js.map +0 -1
  56. package/lib/loaders/tranform-loader.d.ts +0 -18
  57. package/lib/loaders/tranform-loader.js +0 -107
  58. package/lib/loaders/tranform-loader.js.map +0 -1
  59. package/lib/loaders/transformLoader.d.ts +0 -16
  60. package/lib/loaders/transformLoader.js +0 -95
  61. package/lib/loaders/transformLoader.js.map +0 -1
  62. package/lib/module-store.d.ts +0 -10
  63. package/lib/module-store.js +0 -38
  64. package/lib/module-store.js.map +0 -1
  65. package/lib/moduleStore.d.ts +0 -2
  66. package/lib/moduleStore.js.map +0 -1
  67. package/lib/plugins/errorPlugin.d.ts +0 -4
  68. package/lib/plugins/errorPlugin.js +0 -27
  69. package/lib/plugins/errorPlugin.js.map +0 -1
  70. package/lib/plugins/rspack-virtual-modules.d.ts +0 -9
  71. package/lib/plugins/rspack-virtual-modules.js +0 -61
  72. package/lib/plugins/rspack-virtual-modules.js.map +0 -1
  73. package/lib/plugins/virtual-modules-plugin.d.ts +0 -8
  74. package/lib/plugins/virtual-modules-plugin.js +0 -94
  75. package/lib/plugins/virtual-modules-plugin.js.map +0 -1
  76. package/lib/plugins/virtual-modules.d.ts +0 -8
  77. package/lib/plugins/virtual-modules.js +0 -61
  78. package/lib/plugins/virtual-modules.js.map +0 -1
  79. package/lib/plugins/webpack-virtual-modules/index.d.ts +0 -10
  80. package/lib/plugins/webpack-virtual-modules/index.js +0 -264
  81. package/lib/plugins/webpack-virtual-modules/index.js.map +0 -1
  82. package/lib/plugins/webpack-virtual-modules/virtual-stats.d.ts +0 -11
  83. package/lib/plugins/webpack-virtual-modules/virtual-stats.js +0 -43
  84. package/lib/plugins/webpack-virtual-modules/virtual-stats.js.map +0 -1
  85. package/lib/rspack-config.js.map +0 -1
  86. package/lib/rspack-module-store.d.ts +0 -11
  87. package/lib/rspack-module-store.js +0 -48
  88. package/lib/rspack-module-store.js.map +0 -1
  89. package/lib/utils/cache.d.ts +0 -4
  90. package/lib/utils/cache.js +0 -33
  91. package/lib/utils/cache.js.map +0 -1
  92. package/lib/utils/consts.d.ts +0 -3
  93. package/lib/utils/consts.js +0 -18
  94. package/lib/utils/consts.js.map +0 -1
  95. package/lib/utils/index.d.ts +0 -2
  96. package/lib/utils/index.js +0 -12
  97. package/lib/utils/index.js.map +0 -1
  98. package/lib/utils/logger/index.d.ts +0 -30
  99. package/lib/utils/logger/index.js +0 -66
  100. package/lib/utils/logger/index.js.map +0 -1
  101. package/lib/utils/logger/logger.d.ts +0 -30
  102. package/lib/utils/logger/logger.js +0 -66
  103. package/lib/utils/logger/logger.js.map +0 -1
  104. package/lib/utils.js.map +0 -1
  105. package/lib/webpackConfig.js +0 -99
  106. package/lib/webpackConfig.js.map +0 -1
  107. /package/lib/{utils.d.ts → utils/webpack-utils.d.ts} +0 -0
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  ## What is this?
4
4
 
5
- Since the Next.js app directory feature doesn't work with the [@linaria/webpack5-loader](https://github.com/callstack/linaria/tree/master/packages/webpack5-loader) anymore, therefore the [next-linaria](https://github.com/Mistereo/next-linaria) package sadly also doesn't work. This package solves that issue with a custom linaria webpack loader.
5
+ This package provides seamless integration between Next.js and Linaria, a zero-runtime CSS-in-JS solution. It allows you to use Linaria's powerful styling capabilities directly in your Next.js applications, with full support for both the App Router and Pages Router.
6
6
 
7
- ## Try it before you buy it
7
+ ## Try it
8
8
 
9
9
  [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/next-with-linaria?file=app%2Fpage.tsx)
10
10
 
@@ -34,40 +34,39 @@ Since the Next.js app directory feature doesn't work with the [@linaria/webpack5
34
34
 
35
35
  ## Usage
36
36
 
37
- ### Basic Setup
37
+ ### Webpack / Turbopack
38
38
 
39
- ```js
40
- // next.config.js
41
- const withLinaria = require('next-with-linaria');
39
+ ```ts
40
+ // next.config.ts
41
+ import withLinaria, { LinariaConfig } from 'next-with-linaria';
42
42
 
43
- /** @type {import('next-with-linaria').LinariaConfig} */
44
- const config = {
43
+ const config: LinariaConfig = {
45
44
  // ...your next.js config
46
45
  linaria: {
47
- // Linaria options here
46
+ // Linaria options
48
47
  },
49
48
  };
50
- module.exports = withLinaria(config);
49
+
50
+ export default withLinaria(config);
51
51
  ```
52
52
 
53
- ### Rspack Support
53
+ ### Rspack
54
54
 
55
55
  To use Rspack instead of Webpack, you can combine this package with `next-rspack`:
56
56
 
57
- ```js
58
- // next.config.js
59
- const withRspack = require('next-rspack');
60
- const withLinaria = require('next-with-linaria');
57
+ ```ts
58
+ // next.config.ts
59
+ import withRspack from 'next-rspack';
60
+ import withLinaria, { LinariaConfig } from 'next-with-linaria';
61
61
 
62
- /** @type {import('next-with-linaria').LinariaConfig} */
63
- const config = {
62
+ const config: LinariaConfig = {
64
63
  // ...your next.js config
65
64
  linaria: {
66
- // Linaria options here
65
+ // Linaria options
67
66
  },
68
67
  };
69
68
 
70
- module.exports = withRspack(withLinaria(config));
69
+ export default withRspack(withLinaria(config));
71
70
  ```
72
71
 
73
72
  Now you can use linaria in all the places where Next.js also allows you to use [CSS Modules](https://beta.nextjs.org/docs/styling/css-modules). That currently means in every file in the `app` directory and the `pages` directory.
@@ -93,7 +92,9 @@ const config = {
93
92
  module.exports = withLinaria(config);
94
93
  ```
95
94
 
96
- ## Global Styles Restrictions
95
+ ## Restrictions
96
+
97
+ ### Global Styles
97
98
 
98
99
  If you want to use linaria for [global styling](https://beta.nextjs.org/docs/styling/global-styles), you need to place those styles into a file with the suffix `.linaria.global.(js|jsx|ts|tsx)`:
99
100
 
@@ -139,3 +140,39 @@ export default function RootLayout({
139
140
  ```
140
141
 
141
142
  This convention is needed because the loader needs to know which files contain global styles and which don't.
143
+
144
+ ## Limitations
145
+
146
+ - In Webpack and Rspack you can not use linaria styles in server-only files or in server components that import server-only files due to the way HMR works in dev mode.
147
+
148
+ ```tsx
149
+ // app/components/ServerOnlyComponent.tsx
150
+ import 'server-only';
151
+ import { styled } from '@linaria/react';
152
+
153
+ const Container = styled.div`
154
+ color: red;
155
+ `;
156
+
157
+ export default function ServerOnlyComponent() {
158
+ return <Container>Hello World</Container>;
159
+ }
160
+ ```
161
+
162
+ In such a case you need to use the following approach:
163
+
164
+ ```tsx
165
+ // app/components/Container.tsx
166
+ import { styled } from '@linaria/react';
167
+ export const Container = styled.div`
168
+ color: red;
169
+ `;
170
+
171
+ // app/components/ServerOnlyComponent.tsx
172
+ import 'server-only';
173
+ import { Container } from './Container';
174
+
175
+ export default function ServerOnlyComponent() {
176
+ return <Container>Hello World</Container>;
177
+ }
178
+ ```
@@ -1,23 +1,17 @@
1
- import type { NextConfig } from 'next';
2
- import type * as NextServer from 'next/dist/server/config-shared';
3
- import type * as Webpack from 'webpack';
4
- import { LinariaLoaderOptions } from './loaders/transformLoader';
5
- export type LinariaConfig = NextConfig & {
6
- linaria?: Omit<LinariaLoaderOptions, 'moduleStore'>;
7
- };
8
- export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig): {
9
- webpack: (config: Webpack.Configuration, options: NextServer.WebpackConfigContext) => any;
1
+ import { WithLinariaConfig } from './types';
2
+ export declare function addTurbopackConfig({ linaria: linariaOptions, ...config }: WithLinariaConfig): {
3
+ [x: string]: any;
10
4
  allowedDevOrigins?: string[];
11
- exportPathMap?: (defaultMap: NextServer.ExportPathMap, ctx: {
5
+ exportPathMap?: (defaultMap: import("next/dist/server/config-shared").ExportPathMap, ctx: {
12
6
  dev: boolean;
13
7
  dir: string;
14
8
  outDir: string | null;
15
9
  distDir: string;
16
10
  buildId: string;
17
- }) => Promise<NextServer.ExportPathMap> | NextServer.ExportPathMap;
18
- i18n?: NextServer.I18NConfig | null;
19
- eslint?: NextServer.ESLintConfig;
20
- typescript?: NextServer.TypeScriptConfig;
11
+ }) => Promise<import("next/dist/server/config-shared").ExportPathMap> | import("next/dist/server/config-shared").ExportPathMap;
12
+ i18n?: import("next/dist/server/config-shared").I18NConfig | null;
13
+ eslint?: import("next/dist/server/config-shared").ESLintConfig;
14
+ typescript?: import("next/dist/server/config-shared").TypeScriptConfig;
21
15
  headers?: () => Promise<import("next/dist/lib/load-custom-routes").Header[]>;
22
16
  rewrites?: () => Promise<import("next/dist/lib/load-custom-routes").Rewrite[] | {
23
17
  beforeFiles?: import("next/dist/lib/load-custom-routes").Rewrite[];
@@ -26,6 +20,7 @@ export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig):
26
20
  }>;
27
21
  redirects?: () => Promise<import("next/dist/lib/load-custom-routes").Redirect[]>;
28
22
  excludeDefaultMomentLocales?: boolean;
23
+ webpack?: import("next/dist/server/config-shared").NextJsWebpackConfig | null;
29
24
  trailingSlash?: boolean;
30
25
  env?: Record<string, string | undefined>;
31
26
  distDir?: string;
@@ -87,8 +82,8 @@ export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig):
87
82
  removeConsole?: boolean | {
88
83
  exclude?: string[];
89
84
  };
90
- styledComponents?: boolean | NextServer.StyledComponentsConfig;
91
- emotion?: boolean | NextServer.EmotionConfig;
85
+ styledComponents?: boolean | import("next/dist/server/config-shared").StyledComponentsConfig;
86
+ emotion?: boolean | import("next/dist/server/config-shared").EmotionConfig;
92
87
  styledJsx?: boolean | {
93
88
  useLightningcss?: boolean;
94
89
  };
@@ -96,6 +91,7 @@ export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig):
96
91
  };
97
92
  output?: "standalone" | "export";
98
93
  transpilePackages?: string[];
94
+ turbopack?: import("next/dist/server/config-shared").TurbopackOptions;
99
95
  skipMiddlewareUrlNormalize?: boolean;
100
96
  skipTrailingSlashRedirect?: boolean;
101
97
  modularizeImports?: Record<string, {
@@ -103,9 +99,9 @@ export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig):
103
99
  preventFullImport?: boolean;
104
100
  skipDefaultConversion?: boolean;
105
101
  }>;
106
- logging?: NextServer.LoggingConfig | false;
102
+ logging?: import("next/dist/server/config-shared").LoggingConfig | false;
107
103
  expireTime?: number;
108
- experimental?: NextServer.ExperimentalConfig;
104
+ experimental?: import("next/dist/server/config-shared").ExperimentalConfig;
109
105
  bundlePagesRouterDependencies?: boolean;
110
106
  serverExternalPackages?: string[];
111
107
  outputFileTracingRoot?: string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.addTurbopackConfig = addTurbopackConfig;
18
+ const path_1 = __importDefault(require("path"));
19
+ function addTurbopackConfig(_a) {
20
+ var _b, _c;
21
+ var _d;
22
+ var { linaria: linariaOptions } = _a, config = __rest(_a, ["linaria"]);
23
+ (_b = config.turbopack) !== null && _b !== void 0 ? _b : (config.turbopack = {});
24
+ (_c = (_d = config.turbopack).rules) !== null && _c !== void 0 ? _c : (_d.rules = {});
25
+ config.turbopack.rules = Object.assign(Object.assign({}, config.turbopack.rules), { '*.{ts,tsx,js,jsx}': {
26
+ loaders: [
27
+ {
28
+ loader: path_1.default.resolve(__dirname, './loaders/turbopack-transform-loader'),
29
+ options: Object.assign(Object.assign({ sourceMap: process.env.NODE_ENV !== 'production', displayName: process.env.NODE_ENV !== 'production' }, linariaOptions), { babelOptions: {
30
+ presets: ['next/babel', '@wyw-in-js'],
31
+ } }),
32
+ },
33
+ ],
34
+ } });
35
+ return config;
36
+ }
37
+ //# sourceMappingURL=add-turbopack-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-turbopack-config.js","sourceRoot":"","sources":["../src/add-turbopack-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAIA,gDA+BC;AAnCD,gDAAwB;AAIxB,SAAgB,kBAAkB,CAAC,EAGf;;;QAHe,EACjC,OAAO,EAAE,cAAc,OAEL,EADf,MAAM,cAFwB,WAGlC,CADU;IAET,MAAA,MAAM,CAAC,SAAS,oCAAhB,MAAM,CAAC,SAAS,GAAK,EAAE,EAAC;IACxB,YAAA,MAAM,CAAC,SAAS,EAAC,KAAK,uCAAL,KAAK,GAAK,EAAE,EAAC;IAC9B,MAAM,CAAC,SAAS,CAAC,KAAK,mCACjB,MAAM,CAAC,SAAS,CAAC,KAAK,KAGzB,mBAAmB,EAAE;YACnB,OAAO,EAAE;gBACP;oBACE,MAAM,EAAE,cAAI,CAAC,OAAO,CAClB,SAAS,EACT,sCAAsC,CACvC;oBACD,OAAO,gCACL,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAChD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAC/C,cAAc,KACjB,YAAY,EAAE;4BACZ,OAAO,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;yBACtC,GACF;iBACF;aACF;SACF,GACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,13 +1,13 @@
1
1
  import type { NextConfig } from 'next';
2
2
  import type * as NextServer from 'next/dist/server/config-shared';
3
3
  import type * as Webpack from 'webpack';
4
- import { LinariaLoaderOptions } from './loaders/tranform-loader';
4
+ import { LinariaLoaderOptions } from './loaders/webpack-transform-loader';
5
5
  export type LinariaConfig = NextConfig & {
6
- linaria?: Omit<LinariaLoaderOptions, 'moduleStore'> & {
6
+ linaria?: Omit<LinariaLoaderOptions, 'moduleStore' | 'name'> & {
7
7
  fastCheck?: boolean;
8
8
  };
9
9
  };
10
- export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig): {
10
+ export declare function addWebpackConfig({ linaria, ...nextConfig }: LinariaConfig): {
11
11
  webpack: (config: Webpack.Configuration, options: NextServer.WebpackConfigContext) => any;
12
12
  allowedDevOrigins?: string[];
13
13
  exportPathMap?: (defaultMap: NextServer.ExportPathMap, ctx: {
@@ -98,6 +98,7 @@ export default function withLinaria({ linaria, ...nextConfig }: LinariaConfig):
98
98
  };
99
99
  output?: "standalone" | "export";
100
100
  transpilePackages?: string[];
101
+ turbopack?: NextServer.TurbopackOptions;
101
102
  skipMiddlewareUrlNormalize?: boolean;
102
103
  skipTrailingSlashRedirect?: boolean;
103
104
  modularizeImports?: Record<string, {
@@ -14,28 +14,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = withLinaria;
17
+ exports.addWebpackConfig = addWebpackConfig;
18
18
  const path_1 = __importDefault(require("path"));
19
- const tranform_loader_1 = require("./loaders/tranform-loader");
20
- const module_store_1 = __importDefault(require("./module-store"));
21
- const utils_1 = require("./utils");
22
- function traverseLoaders(rules) {
19
+ const consts_1 = require("./loaders/consts");
20
+ const webpack_utils_1 = require("./utils/webpack-utils");
21
+ function modifyCssLoaderConfig(rules) {
23
22
  for (const rule of rules) {
24
23
  if (!rule)
25
24
  continue;
26
- if ((0, utils_1.isCssLoader)(rule)) {
27
- if ((0, utils_1.isCssModule)(rule)) {
25
+ if ((0, webpack_utils_1.isCssLoader)(rule)) {
26
+ if ((0, webpack_utils_1.isCssModule)(rule)) {
28
27
  const nextGetLocalIdent = rule.options.modules.getLocalIdent;
29
28
  const nextMode = rule.options.modules.mode;
30
29
  rule.options.modules.mode = (path) => {
31
- const isGlobal = tranform_loader_1.regexLinariaGlobalCSS.test(path);
30
+ const isGlobal = consts_1.regexIsLinariaGlobalCSSQuery.test(path);
32
31
  if (isGlobal) {
33
32
  return 'local';
34
33
  }
35
34
  return typeof nextMode === 'function' ? nextMode(path) : nextMode;
36
35
  };
37
36
  rule.options.modules.getLocalIdent = (context, _, exportName, ...rest) => {
38
- if (tranform_loader_1.regexLinariaCSS.test(context.resourcePath)) {
37
+ if (consts_1.regexLinariaCSSQuery.test(context.resourceQuery)) {
39
38
  return exportName;
40
39
  }
41
40
  return nextGetLocalIdent(context, _, exportName, ...rest);
@@ -44,48 +43,33 @@ function traverseLoaders(rules) {
44
43
  }
45
44
  if (typeof rule.use === 'object') {
46
45
  const useRules = rule.use;
47
- traverseLoaders(Array.isArray(useRules) ? useRules : [useRules]);
46
+ modifyCssLoaderConfig(Array.isArray(useRules) ? useRules : [useRules]);
48
47
  }
49
48
  if (Array.isArray(rule.oneOf)) {
50
- traverseLoaders(rule.oneOf);
49
+ modifyCssLoaderConfig(rule.oneOf);
51
50
  }
52
51
  }
53
52
  }
54
- let moduleStore;
55
- function withLinaria(_a) {
53
+ function addWebpackConfig(_a) {
56
54
  var { linaria = {} } = _a, nextConfig = __rest(_a, ["linaria"]);
57
- const isRspack = process.env.NEXT_RSPACK;
58
55
  const webpack = (config, options) => {
59
56
  var _a;
60
57
  if (((_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) && config.plugins) {
61
- if (isRspack) {
62
- }
63
- traverseLoaders(config.module.rules);
64
- if (!moduleStore) {
65
- moduleStore = new module_store_1.default(config);
66
- }
67
- config.plugins.push(moduleStore.createStore(config));
58
+ modifyCssLoaderConfig(config.module.rules);
68
59
  config.module.rules.push({
69
- test: tranform_loader_1.regexLinariaCSS,
60
+ test: consts_1.regexLinariaCSS,
61
+ loader: path_1.default.resolve(__dirname, './loaders/webpack-output-css-loader'),
62
+ options: {},
70
63
  exclude: /node_modules/,
71
- use: [
72
- Object.assign(Object.assign({ loader: path_1.default.resolve(__dirname, './loaders/output-css-loader') }, (isRspack ? { parallel: true } : {})), { options: {
73
- moduleStore,
74
- } }),
75
- ],
76
64
  });
77
- const linariaLoaderOptions = Object.assign(Object.assign({ sourceMap: process.env.NODE_ENV !== 'production', displayName: process.env.NODE_ENV !== 'production', babelOptions: {
65
+ const linariaLoaderOptions = Object.assign({ sourceMap: process.env.NODE_ENV !== 'production', displayName: process.env.NODE_ENV !== 'production', babelOptions: {
78
66
  presets: ['next/babel', '@wyw-in-js'],
79
- } }, linaria), { moduleStore });
67
+ } }, linaria);
80
68
  config.module.rules.push({
81
69
  test: /\.(tsx|ts|js|mjs|jsx)$/,
82
70
  exclude: /node_modules/,
83
- use: [
84
- {
85
- loader: path_1.default.resolve(__dirname, './loaders/tranform-loader'),
86
- options: linariaLoaderOptions,
87
- },
88
- ],
71
+ loader: path_1.default.resolve(__dirname, './loaders/webpack-transform-loader'),
72
+ options: linariaLoaderOptions,
89
73
  });
90
74
  }
91
75
  if (typeof nextConfig.webpack === 'function') {
@@ -95,5 +79,4 @@ function withLinaria(_a) {
95
79
  };
96
80
  return Object.assign(Object.assign({}, nextConfig), { webpack });
97
81
  }
98
- module.exports = withLinaria;
99
- //# sourceMappingURL=rspack-config.js.map
82
+ //# sourceMappingURL=add-webpack-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-webpack-config.js","sourceRoot":"","sources":["../src/add-webpack-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA2EA,4CA+CC;AAvHD,gDAAwB;AAGxB,6CAI0B;AAE1B,yDAAiE;AAOjE,SAAS,qBAAqB,CAAC,KAA4B;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,IAAI,IAAA,2BAAW,EAAC,IAAI,CAAC,EAAE,CAAC;YACtB,IAAI,IAAA,2BAAW,EAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;gBAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;gBAG3C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;oBACnC,MAAM,QAAQ,GAAG,qCAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACzD,IAAI,QAAQ,EAAE,CAAC;wBACb,OAAO,OAAO,CAAC;oBACjB,CAAC;oBACD,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;gBACpE,CAAC,CAAC;gBAIF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,GAAG,CACnC,OAAO,EACP,CAAC,EACD,UAAU,EACV,GAAG,IAAI,EACP,EAAE;oBACF,IAAI,6BAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;wBACrD,OAAO,UAAU,CAAC;oBACpB,CAAC;oBACD,OAAO,iBAAiB,CAAC,OAAO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AAE,CAAC,YAAY,EAAE,YAAY,CAAC;iBACtC,IACE,OAAO,CACX,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;gBACvB,IAAI,EAAE,wBAAwB;gBAC9B,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,oCAAoC,CAAC;gBACrE,OAAO,EAAE,oBAAoB;aAC9B,CAAC,CAAC;QACL,CAAC;QAED,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAC7C,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,uCACK,UAAU,KACb,OAAO,IACP;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const LINARIA_MODULE_EXTENSION = ".linaria.module";
2
+ export declare const LINARIA_GLOBAL_EXTENSION = ".linaria.global";
3
+ export declare const regexLinariaCSS: RegExp;
4
+ export declare const regexIsLinariaGlobalCSSQuery: RegExp;
5
+ export declare const regexLinariaCSSQuery: RegExp;
6
+ export declare const regexLinariaSyntaxPattern: RegExp;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.regexLinariaSyntaxPattern = exports.regexLinariaCSSQuery = exports.regexIsLinariaGlobalCSSQuery = exports.regexLinariaCSS = exports.LINARIA_GLOBAL_EXTENSION = exports.LINARIA_MODULE_EXTENSION = void 0;
4
+ exports.LINARIA_MODULE_EXTENSION = '.linaria.module';
5
+ exports.LINARIA_GLOBAL_EXTENSION = '.linaria.global';
6
+ exports.regexLinariaCSS = /\.linaria\.(module|global)\.css$/;
7
+ exports.regexIsLinariaGlobalCSSQuery = /\.linaria\.global\.css\?/;
8
+ exports.regexLinariaCSSQuery = /\.linaria\.(module|global)\.css\?/;
9
+ exports.regexLinariaSyntaxPattern = /(styled[.(]|css`)/;
10
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/loaders/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,wBAAwB,GAAG,iBAAiB,CAAC;AAC7C,QAAA,wBAAwB,GAAG,iBAAiB,CAAC;AAE7C,QAAA,eAAe,GAAG,kCAAkC,CAAC;AACrD,QAAA,4BAA4B,GAAG,0BAA0B,CAAC;AAC1D,QAAA,oBAAoB,GAAG,mCAAmC,CAAC;AAG3D,QAAA,yBAAyB,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { RawLoaderDefinitionFunction } from 'webpack';
2
+ import { LinariaTransformLoaderOptions } from '../types';
3
+ type LoaderType = RawLoaderDefinitionFunction<LinariaTransformLoaderOptions>;
4
+ declare const turbopackTransformLoader: LoaderType;
5
+ export default turbopackTransformLoader;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const transform_1 = require("@wyw-in-js/transform");
18
+ const path_1 = __importDefault(require("path"));
19
+ const fast_check_1 = require("../utils/fast-check");
20
+ const insert_import_1 = require("../utils/insert-import");
21
+ const source_map_1 = require("../utils/source-map");
22
+ const cache = new transform_1.TransformCacheCollection();
23
+ const turbopackTransformLoader = function (content, inputSourceMap) {
24
+ this.async();
25
+ const _a = this.getOptions() || {}, { fastCheck = true } = _a, pluginOptions = __rest(_a, ["fastCheck"]);
26
+ const contentStr = content.toString();
27
+ if (!(0, fast_check_1.performFastCheck)(contentStr, fastCheck)) {
28
+ this.callback(null, contentStr, inputSourceMap);
29
+ return;
30
+ }
31
+ const asyncResolve = async (token, importer) => {
32
+ const context = path_1.default.isAbsolute(importer)
33
+ ? path_1.default.dirname(importer)
34
+ : path_1.default.join(process.cwd(), path_1.default.dirname(importer));
35
+ try {
36
+ const resolve = this.getResolve({});
37
+ const result = await resolve(context, token);
38
+ if (result) {
39
+ this.addDependency(result);
40
+ return result;
41
+ }
42
+ throw new Error(`Cannot resolve ${token} from ${context}`);
43
+ }
44
+ catch (err) {
45
+ console.error(`Error resolving ${token} from ${context}:`, err);
46
+ throw err instanceof Error ? err : new Error(String(err));
47
+ }
48
+ };
49
+ const transformServices = {
50
+ options: {
51
+ filename: this.resourcePath,
52
+ inputSourceMap: (0, source_map_1.convertSourceMap)(inputSourceMap, this.resourcePath),
53
+ root: process.cwd(),
54
+ pluginOptions,
55
+ },
56
+ cache,
57
+ };
58
+ (0, transform_1.transform)(transformServices, contentStr, asyncResolve).then(async (result) => {
59
+ var _a, _b, _c, _d;
60
+ if (result.cssText) {
61
+ await Promise.all((_b = (_a = result.dependencies) === null || _a === void 0 ? void 0 : _a.map((dep) => asyncResolve(dep, this.resourcePath))) !== null && _b !== void 0 ? _b : []);
62
+ const css = Buffer.from(result.cssText).toString('base64');
63
+ const importStatement = `import "data:text/css;base64,${css}";`;
64
+ const finalCode = (0, insert_import_1.insertImportStatement)(result.code, importStatement);
65
+ this.callback(null, finalCode, (_c = result.sourceMap) !== null && _c !== void 0 ? _c : undefined);
66
+ return;
67
+ }
68
+ this.callback(null, result.code, (_d = result.sourceMap) !== null && _d !== void 0 ? _d : undefined);
69
+ }, (err) => this.callback(err));
70
+ };
71
+ exports.default = turbopackTransformLoader;
72
+ //# sourceMappingURL=turbopack-transform-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turbopack-transform-loader.js","sourceRoot":"","sources":["../../src/loaders/turbopack-transform-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,oDAA2E;AAE3E,gDAAwB;AAIxB,oDAAuD;AACvD,0DAA+D;AAC/D,oDAAuD;AAIvD,MAAM,KAAK,GAAG,IAAI,oCAAwB,EAAE,CAAC;AAE7C,MAAM,wBAAwB,GAAe,UAC3C,OAAO,EACP,cAAc;IAEd,IAAI,CAAC,KAAK,EAAE,CAAC;IAEb,MAAM,KAAyC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAhE,EAAE,SAAS,GAAG,IAAI,OAA8C,EAAzC,aAAa,cAApC,aAAsC,CAA0B,CAAC;IAEvE,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAGtC,IAAI,CAAC,IAAA,6BAAgB,EAAC,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;QAChD,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,EACxB,KAAa,EACb,QAAgB,EACC,EAAE;QACnB,MAAM,OAAO,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACvC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YACxB,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC;YAEH,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAEpC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAE7C,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI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M,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YAEtE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,MAAA,MAAM,CAAC,SAAS,mCAAI,SAAS,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAA,MAAM,CAAC,SAAS,mCAAI,SAAS,CAAC,CAAC;IAClE,CAAC,EACD,CAAC,GAAU,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CACnC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,wBAAwB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RawLoaderDefinitionFunction } from 'webpack';
2
+ type LoaderType = RawLoaderDefinitionFunction;
3
+ declare const cssOutputLoader: LoaderType;
4
+ export default cssOutputLoader;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cssOutputLoader = function () {
4
+ const callback = this.async();
5
+ const css = this.resourceQuery.split('.css?css=').pop();
6
+ if (!css) {
7
+ callback(new Error('No CSS part found in resource query'));
8
+ return;
9
+ }
10
+ const decodedCss = Buffer.from(css, 'base64').toString();
11
+ callback(null, decodedCss, undefined);
12
+ };
13
+ exports.default = cssOutputLoader;
14
+ //# sourceMappingURL=webpack-output-css-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-output-css-loader.js","sourceRoot":"","sources":["../../src/loaders/webpack-output-css-loader.ts"],"names":[],"mappings":";;AAIA,MAAM,eAAe,GAAe;IAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAE9B,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC;IAExD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,QAAQ,CAAC,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC,CAAC;QAC3D,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IAEzD,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,kBAAe,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { PluginOptions, Preprocessor } from '@wyw-in-js/transform';
2
+ import type { RawLoaderDefinitionFunction } from 'webpack';
3
+ export type LinariaLoaderOptions = {
4
+ fastCheck?: boolean;
5
+ preprocessor?: Preprocessor;
6
+ sourceMap?: boolean;
7
+ } & Partial<PluginOptions>;
8
+ type LoaderType = RawLoaderDefinitionFunction<LinariaLoaderOptions & {
9
+ name: string;
10
+ }>;
11
+ declare const webpackTransformLoader: LoaderType;
12
+ export default webpackTransformLoader;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const transform_1 = require("@wyw-in-js/transform");
18
+ const path_1 = __importDefault(require("path"));
19
+ const fast_check_1 = require("../utils/fast-check");
20
+ const insert_import_1 = require("../utils/insert-import");
21
+ const source_map_1 = require("../utils/source-map");
22
+ const consts_1 = require("./consts");
23
+ const cache = new transform_1.TransformCacheCollection();
24
+ const webpackTransformLoader = function (content, inputSourceMap) {
25
+ this.async();
26
+ const _a = this.getOptions() || {}, { fastCheck = true } = _a, pluginOptions = __rest(_a, ["fastCheck"]);
27
+ const contentStr = content.toString();
28
+ if (!(0, fast_check_1.performFastCheck)(contentStr, fastCheck)) {
29
+ this.callback(null, contentStr, inputSourceMap);
30
+ return;
31
+ }
32
+ const asyncResolve = (token, importer) => {
33
+ const context = path_1.default.isAbsolute(importer)
34
+ ? path_1.default.dirname(importer)
35
+ : path_1.default.join(process.cwd(), path_1.default.dirname(importer));
36
+ return new Promise((resolve, reject) => {
37
+ this.resolve(context, token, (err, result) => {
38
+ if (err) {
39
+ console.error(err);
40
+ reject(err);
41
+ }
42
+ else if (result) {
43
+ this.addDependency(result);
44
+ resolve(result);
45
+ }
46
+ else {
47
+ reject(new Error(`Cannot resolve ${token}`));
48
+ }
49
+ });
50
+ });
51
+ };
52
+ const filename = path_1.default.basename(this.resourcePath, path_1.default.extname(this.resourcePath));
53
+ const transformServices = {
54
+ options: {
55
+ filename: this.resourcePath,
56
+ inputSourceMap: (0, source_map_1.convertSourceMap)(inputSourceMap, this.resourcePath),
57
+ root: process.cwd(),
58
+ pluginOptions,
59
+ },
60
+ cache,
61
+ };
62
+ (0, transform_1.transform)(transformServices, contentStr, asyncResolve).then(async (result) => {
63
+ var _a, _b, _c, _d;
64
+ if (result.cssText) {
65
+ const { cssText } = result;
66
+ await Promise.all((_b = (_a = result.dependencies) === null || _a === void 0 ? void 0 : _a.map((dep) => {
67
+ return asyncResolve(dep, this.resourcePath);
68
+ })) !== null && _b !== void 0 ? _b : []);
69
+ try {
70
+ const isGlobalStyle = filename.endsWith(consts_1.LINARIA_GLOBAL_EXTENSION);
71
+ const cssSuffix = isGlobalStyle
72
+ ? `${consts_1.LINARIA_GLOBAL_EXTENSION}.css`
73
+ : `${consts_1.LINARIA_MODULE_EXTENSION}.css`;
74
+ const cssFilename = `${filename}${cssSuffix}`;
75
+ const encodedCss = Buffer.from(cssText).toString('base64');
76
+ const importStatement = `import "./${cssFilename}!=!./${filename}?./${cssFilename}?css=${encodedCss}"`;
77
+ const finalCode = (0, insert_import_1.insertImportStatement)(result.code, importStatement);
78
+ this.callback(null, finalCode, (_c = result.sourceMap) !== null && _c !== void 0 ? _c : undefined);
79
+ }
80
+ catch (err) {
81
+ this.callback(err);
82
+ }
83
+ return;
84
+ }
85
+ this.callback(null, result.code, (_d = result.sourceMap) !== null && _d !== void 0 ? _d : undefined);
86
+ }, (err) => this.callback(err));
87
+ };
88
+ exports.default = webpackTransformLoader;
89
+ //# sourceMappingURL=webpack-transform-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-transform-loader.js","sourceRoot":"","sources":["../../src/loaders/webpack-transform-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAKA,oDAA2E;AAE3E,gDAAwB;AAGxB,oDAAuD;AACvD,0DAA+D;AAC/D,oDAAuD;AACvD,qCAA8E;AAiB9E,MAAM,KAAK,GAAG,IAAI,oCAAwB,EAAE,CAAC;AAE7C,MAAM,sBAAsB,GAAe,UAAU,OAAO,EAAE,cAAc;IAE1E,IAAI,CAAC,KAAK,EAAE,CAAC;IAEb,MAAM,KAAyC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAhE,EAAE,SAAS,GAAG,IAAI,OAA8C,EAAzC,aAAa,cAApC,aAAsC,CAA0B,CAAC;IAEvE,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAGtC,IAAI,CAAC,IAAA,6BAAgB,EAAC,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;QAChD,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAmB,EAAE;QACxE,MAAM,OAAO,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ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C;IAClE,CAAC,EACD,CAAC,GAAU,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CACnC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,sBAAsB,CAAC"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { PluginOptions } from '@wyw-in-js/transform';
2
+ import { NextConfig } from 'next';
3
+ export type LinariaTransformLoaderOptions = {
4
+ fastCheck?: boolean;
5
+ } & Partial<Omit<PluginOptions, 'sourceMaps'>>;
6
+ export type WithLinariaConfig = NextConfig & {
7
+ linaria?: LinariaTransformLoaderOptions;
8
+ };
@@ -1,4 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.moduleStore = void 0;
4
- //# sourceMappingURL=moduleStore.js.map
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare function performFastCheck(content: string, fastCheck?: boolean): boolean;