@stylexswc/nextjs-plugin 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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/custom-webpack-loader.d.ts +16 -0
- package/dist/custom-webpack-loader.d.ts.map +1 -0
- package/dist/custom-webpack-loader.js +15 -0
- package/dist/custom-webpack-plugin.d.ts +23 -0
- package/dist/custom-webpack-plugin.d.ts.map +1 -0
- package/dist/custom-webpack-plugin.js +155 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Vladislav Buinovski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# SWC Stylex plugin for Next.js
|
|
2
|
+
|
|
3
|
+
Next.js plugin for an unofficial
|
|
4
|
+
[`StyleX SWC`](https://github.com/dwlad90/stylex-swc-plugin/tree/master/packages/swc-plugin)
|
|
5
|
+
plugin.
|
|
6
|
+
|
|
7
|
+
## Why SWC instead of Babel
|
|
8
|
+
|
|
9
|
+
Since version 12, Next.js uses SWC Compiler by default.
|
|
10
|
+
[According to Vercel](https://nextjs.org/docs/architecture/nextjs-compiler),
|
|
11
|
+
compilation using the SWC Compiler is 17x faster than Babel.
|
|
12
|
+
|
|
13
|
+
However, if you have a Babel config, the application will out put of SWC
|
|
14
|
+
Compiler and continue to use Babel.
|
|
15
|
+
|
|
16
|
+
This plugin allows us to use StyleX and take advantage of SWC Compiler.
|
|
17
|
+
|
|
18
|
+
**The usage of StyleX does not change**, all changes are internal. All you need
|
|
19
|
+
to do, is install SWC StyleX plugin and update Next.js config.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install the package and SWC plugin by using:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install --save-dev @stylexswc/nextjs-plugin
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Please install `@stylexswc/swc-plugin` if you haven't done so already:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install --save-dev @stylexswc/swc-plugin
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
Modify Next.js config. For example:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
/** @type {import('next').NextConfig} */
|
|
41
|
+
const stylexPlugin = require('@stylexswc/nextjs-plugin');
|
|
42
|
+
|
|
43
|
+
const nextConfig = {
|
|
44
|
+
// Configure `pageExtensions` to include MDX files
|
|
45
|
+
pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'],
|
|
46
|
+
transpilePackages: ['@stylexjs/open-props'],
|
|
47
|
+
// Optionally, add any other Next.js config below
|
|
48
|
+
swcMinify: true,
|
|
49
|
+
experimental: {
|
|
50
|
+
swcPlugins: [
|
|
51
|
+
'@stylexswc/swc-plugin',
|
|
52
|
+
{
|
|
53
|
+
dev: false,
|
|
54
|
+
runtimeInjection: false,
|
|
55
|
+
genConditionalClasses: true,
|
|
56
|
+
treeshakeCompensation: true,
|
|
57
|
+
unstable_moduleResolution: {
|
|
58
|
+
type: 'commonJS',
|
|
59
|
+
rootDir: __dirname,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
module.exports = stylexPlugin({
|
|
67
|
+
rootDir: __dirname,
|
|
68
|
+
})(nextConfig);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Examples
|
|
72
|
+
|
|
73
|
+
- [Example repo](https://github.com/Dwlad90/nextjs-app-dir-stylex)
|
|
74
|
+
- [CodeSandbox with example repo](https://codesandbox.io/p/github/Dwlad90/nextjs-app-dir-stylex/main)
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
- [StyleX Documentation](https://stylexjs.com)
|
|
79
|
+
- [SWC plugin for StyleX](https://github.com/Dwlad90/stylex-swc-plugin/tree/master/packages/swc-plugin)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,MAAM,MAAM,yBAAyB,CAAC,OAAO,GAAG,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,GAAG,EAEnF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as webpack from 'webpack';
|
|
2
|
+
import { type SupplementedLoaderContext } from './constants';
|
|
3
|
+
export type WebpackLoaderOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Please never use this feature, it will be removed without further notice.
|
|
6
|
+
*/
|
|
7
|
+
stylexPlugin?: {
|
|
8
|
+
transformCode: (code: string, filePath: string, logger?: ReturnType<webpack.Compiler['getInfrastructureLogger']>) => Promise<{
|
|
9
|
+
code: string;
|
|
10
|
+
map: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
declare function stylexLoader(this: SupplementedLoaderContext<WebpackLoaderOptions>, inputCode: string): void;
|
|
15
|
+
export default stylexLoader;
|
|
16
|
+
//# sourceMappingURL=custom-webpack-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-webpack-loader.d.ts","sourceRoot":"","sources":["../src/custom-webpack-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC,OAAO,EAAe,KAAK,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE1E,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,YAAY,CAAC,EAAE;QACb,aAAa,EAAE,CACb,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,KAC7D,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC7C,CAAC;CACH,CAAC;AAIF,iBAAS,YAAY,CAAC,IAAI,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,EAAE,SAAS,EAAE,MAAM,QAc7F;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("./constants");
|
|
4
|
+
function stylexLoader(inputCode) {
|
|
5
|
+
const callback = this.async();
|
|
6
|
+
const { stylexPlugin } = this.getOptions();
|
|
7
|
+
const logger = this._compiler?.getInfrastructureLogger(constants_1.PLUGIN_NAME);
|
|
8
|
+
stylexPlugin?.transformCode(inputCode, this.resourcePath, logger).then(({ code, map }) => {
|
|
9
|
+
callback(null, code, map);
|
|
10
|
+
}, (error) => {
|
|
11
|
+
callback(error);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.default = stylexLoader;
|
|
15
|
+
module.exports = stylexLoader;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Compiler } from 'webpack';
|
|
2
|
+
declare class StylexPlugin {
|
|
3
|
+
filesInLastRun: any;
|
|
4
|
+
filePath: any;
|
|
5
|
+
dev: any;
|
|
6
|
+
appendTo: any;
|
|
7
|
+
filename: any;
|
|
8
|
+
babelConfig: any;
|
|
9
|
+
stylexImports: any[];
|
|
10
|
+
babelPlugin: any;
|
|
11
|
+
useCSSLayers: any;
|
|
12
|
+
constructor({ dev, appendTo, filename, stylexImports, useCSSLayers, }?: any);
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
transformCode(inputCode: string, filename: string, logger: any): Promise<{
|
|
15
|
+
code: string;
|
|
16
|
+
map: null;
|
|
17
|
+
} | {
|
|
18
|
+
code: string;
|
|
19
|
+
map?: undefined;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
export default StylexPlugin;
|
|
23
|
+
//# sourceMappingURL=custom-webpack-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-webpack-plugin.d.ts","sourceRoot":"","sources":["../src/custom-webpack-plugin.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,SAAS,CAAC;AAetD,cAAM,YAAY;IAChB,cAAc,EAAE,GAAG,CAAQ;IAC3B,QAAQ,EAAE,GAAG,CAAQ;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;IACd,WAAW,EAAE,GAAG,CAAC;IACjB,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,WAAW,EAAE,GAAG,CAAC;IACjB,YAAY,EAAE,GAAG,CAAC;gBAEN,EACV,GAAgB,EAChB,QAAQ,EACR,QAAsD,EACtD,aAA8C,EAC9C,YAAoB,GACrB,GAAE,GAAQ;IASX,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAgGlB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;;;;;;;CA2DrE;AACD,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const babel_plugin_1 = __importDefault(require("@stylexjs/babel-plugin"));
|
|
8
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
9
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
const { NormalModule, Compilation } = webpack_1.default;
|
|
11
|
+
const PLUGIN_NAME = 'stylex';
|
|
12
|
+
const IS_DEV_ENV = process.env.NODE_ENV === 'development' || process.env.BABEL_ENV === 'development';
|
|
13
|
+
const { RawSource, ConcatSource } = webpack_1.default.sources;
|
|
14
|
+
const stylexRules = {};
|
|
15
|
+
const cssFiles = new Set();
|
|
16
|
+
const compilers = new Set();
|
|
17
|
+
class StylexPlugin {
|
|
18
|
+
filesInLastRun = null;
|
|
19
|
+
filePath = null;
|
|
20
|
+
dev;
|
|
21
|
+
appendTo;
|
|
22
|
+
filename;
|
|
23
|
+
babelConfig;
|
|
24
|
+
stylexImports;
|
|
25
|
+
babelPlugin;
|
|
26
|
+
useCSSLayers;
|
|
27
|
+
constructor({ dev = IS_DEV_ENV, appendTo, filename = appendTo == null ? 'stylex.css' : undefined, stylexImports = ['stylex', '@stylexjs/stylex'], useCSSLayers = false, } = {}) {
|
|
28
|
+
this.dev = dev;
|
|
29
|
+
this.appendTo = appendTo;
|
|
30
|
+
this.filename = filename;
|
|
31
|
+
this.stylexImports = stylexImports;
|
|
32
|
+
this.useCSSLayers = useCSSLayers;
|
|
33
|
+
}
|
|
34
|
+
apply(compiler) {
|
|
35
|
+
compiler.hooks.make.tap(PLUGIN_NAME, compilation => {
|
|
36
|
+
// Apply loader to JS modules.
|
|
37
|
+
NormalModule.getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (_, module) => {
|
|
38
|
+
if (
|
|
39
|
+
// JavaScript (and Flow) modules
|
|
40
|
+
/\.jsx?/.test(path_1.default.extname(module.resource)) ||
|
|
41
|
+
// TypeScript modules
|
|
42
|
+
/\.tsx?/.test(path_1.default.extname(module.resource))) {
|
|
43
|
+
// We use .push() here instead of .unshift()
|
|
44
|
+
// Webpack usually runs loaders in reverse order and we want to ideally run
|
|
45
|
+
// our loader before anything else.
|
|
46
|
+
module.loaders.unshift({
|
|
47
|
+
loader: path_1.default.resolve(__dirname, 'custom-webpack-loader.js'),
|
|
48
|
+
options: { stylexPlugin: this },
|
|
49
|
+
ident: null,
|
|
50
|
+
type: null,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (
|
|
54
|
+
// JavaScript (and Flow) modules
|
|
55
|
+
/\.css/.test(path_1.default.extname(module.resource))) {
|
|
56
|
+
cssFiles.add(module.resource);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const getStyleXRules = () => {
|
|
60
|
+
if (Object.keys(stylexRules).length === 0) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
// Take styles for the modules that were included in the last compilation.
|
|
64
|
+
const allRules = Object.keys(stylexRules)
|
|
65
|
+
.map(filename => stylexRules[filename])
|
|
66
|
+
.filter(Boolean)
|
|
67
|
+
.flat();
|
|
68
|
+
return babel_plugin_1.default.processStylexRules(allRules, this.useCSSLayers);
|
|
69
|
+
};
|
|
70
|
+
if (this.appendTo) {
|
|
71
|
+
compilation.hooks.processAssets.tap({
|
|
72
|
+
name: PLUGIN_NAME,
|
|
73
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS, // see below for more stages
|
|
74
|
+
}, assets => {
|
|
75
|
+
const cssFileName = Object.keys(assets).find(typeof this.appendTo === 'function'
|
|
76
|
+
? this.appendTo
|
|
77
|
+
: filename => filename.endsWith(this.appendTo));
|
|
78
|
+
const stylexCSS = getStyleXRules();
|
|
79
|
+
if (cssFileName && stylexCSS != null) {
|
|
80
|
+
this.filePath = path_1.default.join(process.cwd(), '.next', cssFileName);
|
|
81
|
+
const source = assets?.[cssFileName]?.source();
|
|
82
|
+
if (source) {
|
|
83
|
+
const updatedSource = new ConcatSource(new RawSource(source), new RawSource(stylexCSS));
|
|
84
|
+
compilation.updateAsset(cssFileName, updatedSource);
|
|
85
|
+
compilers.add(compiler);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Consume collected rules and emit the stylex CSS asset
|
|
92
|
+
compilation.hooks.additionalAssets.tap(PLUGIN_NAME, () => {
|
|
93
|
+
try {
|
|
94
|
+
const collectedCSS = getStyleXRules();
|
|
95
|
+
if (collectedCSS) {
|
|
96
|
+
console.log('emitting asset', this.filename, collectedCSS);
|
|
97
|
+
compilation.emitAsset(this.filename, new RawSource(collectedCSS));
|
|
98
|
+
promises_1.default.writeFile(this.filename, collectedCSS).then(() => console.log('wrote file', this.filename));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
compilation.errors.push(e);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// This function is not called by Webpack directly.
|
|
109
|
+
// Instead, `NormalModule.getCompilationHooks` is used to inject a loader
|
|
110
|
+
// for JS modules. The loader than calls this function.
|
|
111
|
+
async transformCode(inputCode, filename, logger) {
|
|
112
|
+
const originalSource = inputCode;
|
|
113
|
+
if (inputCode.includes('Welcome to my MDX page'))
|
|
114
|
+
console.log('originalSource: ', originalSource);
|
|
115
|
+
if (this.stylexImports.some(importName => originalSource.includes(importName))) {
|
|
116
|
+
let metadataStr = '[]';
|
|
117
|
+
const code = originalSource.replace(/\/\/*__stylex_metadata_start__(?<metadata>.+)__stylex_metadata_end__/, (...args) => {
|
|
118
|
+
metadataStr = args.at(-1)?.metadata.split('"__stylex_metadata_end__')[0];
|
|
119
|
+
return '';
|
|
120
|
+
});
|
|
121
|
+
const metadata = { stylex: [] };
|
|
122
|
+
try {
|
|
123
|
+
metadata.stylex = JSON.parse(metadataStr);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
console.error('error parsing metadata', e);
|
|
127
|
+
}
|
|
128
|
+
const map = null;
|
|
129
|
+
if (metadata.stylex != null && metadata.stylex.length > 0) {
|
|
130
|
+
const oldRules = stylexRules[filename] || [];
|
|
131
|
+
stylexRules[filename] = metadata.stylex?.map((rule) => [rule.class_name, rule.style, rule.priority]);
|
|
132
|
+
logger.debug(`Read stylex styles from ${filename}:`, metadata.stylex);
|
|
133
|
+
const oldClassNames = new Set(oldRules.map(rule => rule[0]));
|
|
134
|
+
const newClassNames = new Set(metadata.stylex.map(rule => rule[0]));
|
|
135
|
+
// If there are any new classNames in the output we need to recompile
|
|
136
|
+
// the CSS bundle.
|
|
137
|
+
if (oldClassNames.size !== newClassNames.size ||
|
|
138
|
+
[...newClassNames].some(className => !oldClassNames.has(className)) ||
|
|
139
|
+
filename.endsWith('.stylex.ts') ||
|
|
140
|
+
filename.endsWith('.stylex.tsx') ||
|
|
141
|
+
filename.endsWith('.stylex.js')) {
|
|
142
|
+
compilers.forEach(compiler => {
|
|
143
|
+
cssFiles.forEach(cssFile => {
|
|
144
|
+
compiler.watchFileSystem.watcher.fileWatchers.get(cssFile).watcher.emit('change');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return { code, map };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { code: inputCode };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.default = StylexPlugin;
|
|
155
|
+
module.exports = StylexPlugin;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
2
|
+
import type { NextConfig } from 'next';
|
|
3
|
+
import type { ConfigurationContext } from 'next/dist/build/webpack/config/utils';
|
|
4
|
+
import type { WebpackConfigContext } from 'next/dist/server/config-shared';
|
|
5
|
+
declare function StylexNextJSPlugin({ rootDir, filename, ...pluginOptions }: any): (nextConfig?: NextConfig) => {
|
|
6
|
+
transpilePackages: string[];
|
|
7
|
+
webpack(config: Configuration & ConfigurationContext, options: WebpackConfigContext): Configuration & ConfigurationContext;
|
|
8
|
+
exportPathMap?: ((defaultMap: import("next/dist/server/config-shared").ExportPathMap, ctx: {
|
|
9
|
+
dev: boolean;
|
|
10
|
+
dir: string;
|
|
11
|
+
outDir: string | null;
|
|
12
|
+
distDir: string;
|
|
13
|
+
buildId: string;
|
|
14
|
+
}) => import("next/dist/server/config-shared").ExportPathMap | Promise<import("next/dist/server/config-shared").ExportPathMap>) | undefined;
|
|
15
|
+
i18n?: import("next/dist/server/config-shared").I18NConfig | null | undefined;
|
|
16
|
+
eslint?: import("next/dist/server/config-shared").ESLintConfig | undefined;
|
|
17
|
+
typescript?: import("next/dist/server/config-shared").TypeScriptConfig | undefined;
|
|
18
|
+
headers?: (() => Promise<import("next/dist/lib/load-custom-routes").Header[]>) | undefined;
|
|
19
|
+
rewrites?: (() => Promise<import("next/dist/lib/load-custom-routes").Rewrite[] | {
|
|
20
|
+
beforeFiles: import("next/dist/lib/load-custom-routes").Rewrite[];
|
|
21
|
+
afterFiles: import("next/dist/lib/load-custom-routes").Rewrite[];
|
|
22
|
+
fallback: import("next/dist/lib/load-custom-routes").Rewrite[];
|
|
23
|
+
}>) | undefined;
|
|
24
|
+
redirects?: (() => Promise<import("next/dist/lib/load-custom-routes").Redirect[]>) | undefined;
|
|
25
|
+
excludeDefaultMomentLocales?: boolean | undefined;
|
|
26
|
+
trailingSlash?: boolean | undefined;
|
|
27
|
+
env?: Record<string, string | undefined> | undefined;
|
|
28
|
+
distDir?: string | undefined;
|
|
29
|
+
cleanDistDir?: boolean | undefined;
|
|
30
|
+
assetPrefix?: string | undefined;
|
|
31
|
+
cacheHandler?: string | undefined;
|
|
32
|
+
cacheMaxMemorySize?: number | undefined;
|
|
33
|
+
useFileSystemPublicRoutes?: boolean | undefined;
|
|
34
|
+
generateBuildId?: (() => string | Promise<string | null> | null) | undefined;
|
|
35
|
+
generateEtags?: boolean | undefined;
|
|
36
|
+
pageExtensions?: string[] | undefined;
|
|
37
|
+
compress?: boolean | undefined;
|
|
38
|
+
analyticsId?: string | undefined;
|
|
39
|
+
poweredByHeader?: boolean | undefined;
|
|
40
|
+
images?: Partial<import("next/dist/shared/lib/image-config").ImageConfigComplete> | undefined;
|
|
41
|
+
devIndicators?: {
|
|
42
|
+
buildActivity?: boolean | undefined;
|
|
43
|
+
buildActivityPosition?: "bottom-right" | "bottom-left" | "top-right" | "top-left" | undefined;
|
|
44
|
+
} | undefined;
|
|
45
|
+
onDemandEntries?: {
|
|
46
|
+
maxInactiveAge?: number | undefined;
|
|
47
|
+
pagesBufferLength?: number | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
amp?: {
|
|
50
|
+
canonicalBase?: string | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
deploymentId?: string | undefined;
|
|
53
|
+
basePath?: string | undefined;
|
|
54
|
+
sassOptions?: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
} | undefined;
|
|
57
|
+
productionBrowserSourceMaps?: boolean | undefined;
|
|
58
|
+
optimizeFonts?: boolean | undefined;
|
|
59
|
+
reactProductionProfiling?: boolean | undefined;
|
|
60
|
+
reactStrictMode?: boolean | null | undefined;
|
|
61
|
+
publicRuntimeConfig?: {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
} | undefined;
|
|
64
|
+
serverRuntimeConfig?: {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
} | undefined;
|
|
67
|
+
httpAgentOptions?: {
|
|
68
|
+
keepAlive?: boolean | undefined;
|
|
69
|
+
} | undefined;
|
|
70
|
+
outputFileTracing?: boolean | undefined;
|
|
71
|
+
staticPageGenerationTimeout?: number | undefined;
|
|
72
|
+
crossOrigin?: "anonymous" | "use-credentials" | undefined;
|
|
73
|
+
swcMinify?: boolean | undefined;
|
|
74
|
+
compiler?: {
|
|
75
|
+
reactRemoveProperties?: boolean | {
|
|
76
|
+
properties?: string[] | undefined;
|
|
77
|
+
} | undefined;
|
|
78
|
+
relay?: {
|
|
79
|
+
src: string;
|
|
80
|
+
artifactDirectory?: string | undefined;
|
|
81
|
+
language?: "typescript" | "javascript" | "flow" | undefined;
|
|
82
|
+
eagerEsModules?: boolean | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
removeConsole?: boolean | {
|
|
85
|
+
exclude?: string[] | undefined;
|
|
86
|
+
} | undefined;
|
|
87
|
+
styledComponents?: boolean | import("next/dist/server/config-shared").StyledComponentsConfig | undefined;
|
|
88
|
+
emotion?: boolean | import("next/dist/server/config-shared").EmotionConfig | undefined;
|
|
89
|
+
styledJsx?: boolean | {
|
|
90
|
+
useLightningcss?: boolean | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
} | undefined;
|
|
93
|
+
output?: "standalone" | "export" | undefined;
|
|
94
|
+
skipMiddlewareUrlNormalize?: boolean | undefined;
|
|
95
|
+
skipTrailingSlashRedirect?: boolean | undefined;
|
|
96
|
+
modularizeImports?: Record<string, {
|
|
97
|
+
transform: string | Record<string, string>;
|
|
98
|
+
preventFullImport?: boolean | undefined;
|
|
99
|
+
skipDefaultConversion?: boolean | undefined;
|
|
100
|
+
}> | undefined;
|
|
101
|
+
logging?: {
|
|
102
|
+
fetches?: {
|
|
103
|
+
fullUrl?: boolean | undefined;
|
|
104
|
+
} | undefined;
|
|
105
|
+
} | undefined;
|
|
106
|
+
experimental?: import("next/dist/server/config-shared").ExperimentalConfig | undefined;
|
|
107
|
+
};
|
|
108
|
+
export default StylexNextJSPlugin;
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAG3E,iBAAS,kBAAkB,CAAC,EAAE,OAAO,EAAE,QAA8B,EAAE,GAAG,aAAa,EAAE,EAAE,GAAG,iBACxE,UAAU;;oBAIV,aAAa,GAAG,oBAAoB,WAAW,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8CxF;AAED,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const custom_webpack_plugin_1 = __importDefault(require("./custom-webpack-plugin"));
|
|
7
|
+
let count = 0;
|
|
8
|
+
function StylexNextJSPlugin({ rootDir, filename = 'stylex-bundle.css', ...pluginOptions }) {
|
|
9
|
+
return (nextConfig = {}) => {
|
|
10
|
+
return {
|
|
11
|
+
...nextConfig,
|
|
12
|
+
transpilePackages: [...(nextConfig.transpilePackages || []), '@stylexjs/open-props'],
|
|
13
|
+
webpack(config, options) {
|
|
14
|
+
if (typeof nextConfig.webpack === 'function') {
|
|
15
|
+
config = nextConfig.webpack(config, options);
|
|
16
|
+
}
|
|
17
|
+
const { buildId, dev, isServer } = options;
|
|
18
|
+
console.log([
|
|
19
|
+
'!!!GETTING WEBPACK CONFIG!!!',
|
|
20
|
+
'======================',
|
|
21
|
+
`Count: ${++count}`,
|
|
22
|
+
`Build ID: ${buildId}`,
|
|
23
|
+
`Server: ${isServer}`,
|
|
24
|
+
`Env: ${dev ? 'dev' : 'prod'}`,
|
|
25
|
+
].join('\n'));
|
|
26
|
+
if (config.optimization?.splitChunks) {
|
|
27
|
+
config.optimization.splitChunks ||= { cacheGroups: {} };
|
|
28
|
+
if (config.optimization.splitChunks.cacheGroups) {
|
|
29
|
+
config.optimization.splitChunks.cacheGroups.stylex = {
|
|
30
|
+
name: 'stylex',
|
|
31
|
+
chunks: 'all',
|
|
32
|
+
test: /\.css$/,
|
|
33
|
+
enforce: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const webpackPluginOptions = {
|
|
38
|
+
rootDir,
|
|
39
|
+
appendTo: (name) => name.endsWith('.css'),
|
|
40
|
+
filename,
|
|
41
|
+
dev,
|
|
42
|
+
...pluginOptions,
|
|
43
|
+
};
|
|
44
|
+
const stylexPlugin = new custom_webpack_plugin_1.default(webpackPluginOptions);
|
|
45
|
+
config.plugins?.push(stylexPlugin);
|
|
46
|
+
return config;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.default = StylexNextJSPlugin;
|
|
52
|
+
module.exports = StylexNextJSPlugin;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stylexswc/nextjs-plugin",
|
|
3
|
+
"description": "Stylex NextJS plugin with swc plugin",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"config": {
|
|
6
|
+
"scripty": {
|
|
7
|
+
"path": "../../scripts/packages"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@babel/types": "^7.23.9",
|
|
12
|
+
"@types/babel__core": "^7.20.5",
|
|
13
|
+
"@types/node": "^20.12.11",
|
|
14
|
+
"next": "^14.0.1",
|
|
15
|
+
"react": "^18.2.0",
|
|
16
|
+
"react-dom": "^18.2.0",
|
|
17
|
+
"webpack": "^5.88.2",
|
|
18
|
+
"@stylexswc/eslint-config": "0.1.0",
|
|
19
|
+
"@stylexswc/typescript-config": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"next",
|
|
26
|
+
"nextjs",
|
|
27
|
+
"nextjs-plugin",
|
|
28
|
+
"stylex"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"main": "dist/index.js",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@stylexjs/babel-plugin": "^0.6.1",
|
|
34
|
+
"next": ">=14.0.1"
|
|
35
|
+
},
|
|
36
|
+
"private": false,
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": "dwlad90/stylex-swc-plugin",
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "scripty --ts",
|
|
44
|
+
"clean": "del-cli dist",
|
|
45
|
+
"precommit": "lint-staged",
|
|
46
|
+
"prepush": "lint-prepush",
|
|
47
|
+
"test": "echo \"Error: no test specified\" && exit 0"
|
|
48
|
+
}
|
|
49
|
+
}
|