unplugin-stylex 0.0.2 → 0.2.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/.eslintrc.json +4 -6
- package/.github/renovate.json +27 -0
- package/.github/workflows/release.yml +13 -0
- package/.github/workflows/typos.yml +15 -0
- package/README.md +9 -7
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7MXMBS5H.js +190 -0
- package/dist/chunk-NVMQARFA.cjs +190 -0
- package/dist/chunk-ZBPRDZS4.cjs +1 -0
- package/dist/esbuild.cjs +4 -2
- package/dist/esbuild.d.cts +10 -5
- package/dist/esbuild.d.ts +10 -5
- package/dist/esbuild.js +4 -2
- package/dist/index.cjs +3 -2
- package/dist/index.d.cts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.d.cts +12 -1
- package/dist/rollup.d.ts +12 -1
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +4 -2
- package/dist/rspack.d.cts +11 -5
- package/dist/rspack.d.ts +11 -5
- package/dist/rspack.js +4 -2
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +7 -7
- package/dist/types.d.ts +7 -7
- package/dist/types.js +1 -0
- package/dist/vite.cjs +4 -2
- package/dist/vite.d.cts +10 -5
- package/dist/vite.d.ts +10 -5
- package/dist/vite.js +4 -2
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.d.cts +12 -1
- package/dist/webpack.d.ts +12 -1
- package/dist/webpack.js +1 -1
- package/jsr.json +20 -0
- package/package.json +8 -3
- package/src/core/build.ts +9 -0
- package/src/core/{utils.ts → options.ts} +9 -9
- package/src/core/plugins.ts +12 -0
- package/src/core/transformer.ts +31 -48
- package/src/esbuild.ts +27 -2
- package/src/index.ts +64 -24
- package/src/rollup.ts +12 -2
- package/src/rspack.ts +27 -2
- package/src/types.ts +8 -7
- package/src/vite.ts +26 -2
- package/src/webpack.ts +12 -2
- package/typos.toml +10 -0
- package/vitest.config.ts +2 -2
- package/dist/chunk-D3OQCQYP.cjs +0 -152
- package/dist/chunk-XQ5JPTTJ.js +0 -152
package/src/index.ts
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as path from 'node:path'
|
|
2
|
+
|
|
3
3
|
import { createUnplugin } from 'unplugin'
|
|
4
|
-
import type { UnpluginFactory } from 'unplugin'
|
|
4
|
+
import type { UnpluginFactory, UnpluginInstance } from 'unplugin'
|
|
5
|
+
import type { BuildOptions } from 'vite'
|
|
5
6
|
|
|
7
|
+
import { buildStylexRules } from './core/build'
|
|
6
8
|
import { PLUGIN_NAME } from './core/constants'
|
|
7
|
-
import { getOptions } from './core/
|
|
9
|
+
import { getOptions } from './core/options'
|
|
8
10
|
import { transformer } from './core/transformer'
|
|
9
11
|
import type { UnpluginStylexOptions } from './types'
|
|
10
12
|
|
|
11
13
|
export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined> = (rawOptions = {}) => {
|
|
12
14
|
const options = getOptions(rawOptions)
|
|
13
|
-
const filter = createFilter(options.include, options.exclude)
|
|
14
15
|
const stylexRules = {}
|
|
15
|
-
let
|
|
16
|
+
let viteConfig: { build: BuildOptions | undefined; base: string | undefined; } | null = null
|
|
16
17
|
|
|
17
18
|
return {
|
|
18
19
|
name: PLUGIN_NAME,
|
|
19
|
-
enforce: options.enforce,
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
async transform(code, id) {
|
|
22
|
+
const dir = path.dirname(id)
|
|
23
|
+
const basename = path.basename(id)
|
|
24
|
+
const file = path.join(dir, basename.includes('?') ? basename.split('?')[0] : basename)
|
|
25
|
+
|
|
26
|
+
if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
24
29
|
|
|
25
|
-
async transform(source, id) {
|
|
26
30
|
const context = {
|
|
31
|
+
id: file,
|
|
32
|
+
inputCode: code,
|
|
27
33
|
pluginContext: this,
|
|
28
34
|
options,
|
|
29
|
-
source,
|
|
30
|
-
id,
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
try {
|
|
@@ -39,16 +43,16 @@ export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>
|
|
|
39
43
|
|
|
40
44
|
return result
|
|
41
45
|
} catch (error) {
|
|
46
|
+
console.error('transform::error::', error)
|
|
42
47
|
this.error(error)
|
|
43
48
|
}
|
|
44
49
|
},
|
|
45
50
|
|
|
46
51
|
buildEnd() {
|
|
47
|
-
const rules = Object.values(stylexRules).flat()
|
|
48
|
-
if (rules.length === 0) return
|
|
49
|
-
|
|
50
|
-
const collectedCSS = (stylexBabelPlugin as any).processStylexRules(rules, options.stylex.useCSSLayers)
|
|
51
52
|
const fileName = options.stylex.filename
|
|
53
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
|
|
54
|
+
|
|
55
|
+
if (!collectedCSS) return
|
|
52
56
|
|
|
53
57
|
this.emitFile({
|
|
54
58
|
fileName,
|
|
@@ -56,27 +60,63 @@ export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>
|
|
|
56
60
|
type: 'asset',
|
|
57
61
|
})
|
|
58
62
|
},
|
|
63
|
+
|
|
59
64
|
vite: {
|
|
60
65
|
config(config) {
|
|
61
|
-
|
|
66
|
+
viteConfig = {
|
|
67
|
+
build: config.build,
|
|
68
|
+
base: config.base,
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
configResolved(config) {
|
|
73
|
+
config.optimizeDeps.exclude = config.optimizeDeps.exclude || []
|
|
74
|
+
config.optimizeDeps.exclude.push('@stylexjs/open-props')
|
|
62
75
|
},
|
|
76
|
+
|
|
63
77
|
buildEnd() {
|
|
64
|
-
const
|
|
65
|
-
|
|
78
|
+
const fileName = `${viteConfig!.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
79
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
|
|
66
80
|
|
|
67
|
-
|
|
68
|
-
const fileName = `${viteBuildConfig.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
81
|
+
if (!collectedCSS) return
|
|
69
82
|
|
|
70
83
|
this.emitFile({
|
|
71
84
|
fileName,
|
|
72
85
|
source: collectedCSS,
|
|
73
86
|
type: 'asset',
|
|
74
87
|
})
|
|
75
|
-
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
transformIndexHtml(html, ctx) {
|
|
91
|
+
const fileName = `${viteConfig!.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
92
|
+
const css = ctx.bundle?.[fileName]
|
|
93
|
+
|
|
94
|
+
if (!css) {
|
|
95
|
+
return html
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const publicPath = path.posix.join(
|
|
99
|
+
viteConfig!.base ?? '/',
|
|
100
|
+
fileName.replace(/\\/g, '/')
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
tag: 'link',
|
|
106
|
+
attrs: {
|
|
107
|
+
rel: 'stylesheet',
|
|
108
|
+
href: publicPath,
|
|
109
|
+
},
|
|
110
|
+
injectTo: 'head',
|
|
111
|
+
},
|
|
112
|
+
]
|
|
113
|
+
},
|
|
76
114
|
},
|
|
77
115
|
}
|
|
78
116
|
}
|
|
79
117
|
|
|
80
|
-
export const unplugin = createUnplugin(unpluginFactory)
|
|
118
|
+
export const unplugin: UnpluginInstance<UnpluginStylexOptions | undefined, boolean> = createUnplugin(unpluginFactory)
|
|
119
|
+
|
|
120
|
+
export * from './types'
|
|
81
121
|
|
|
82
122
|
export default unplugin
|
package/src/rollup.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This entry file is for Rollup plugin.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import { isDevelopment } from './core/constants'
|
|
8
|
+
import type { UnpluginStylexOptions } from './types'
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Note: Current, please use @stylexjs/rollup-plugin
|
|
12
|
+
*/
|
|
13
|
+
export default (options?: UnpluginStylexOptions) => {
|
|
4
14
|
if (isDevelopment || options?.dev) {
|
|
5
|
-
throw new Error(
|
|
15
|
+
throw new Error('If you want to use this plugin through rollup, please use "@stylexjs/rollup-plugin" instead')
|
|
6
16
|
}
|
|
7
17
|
}
|
package/src/rspack.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This entry file is for Rspac plugin.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import { createRspackPlugin } from 'unplugin'
|
|
2
|
-
import {
|
|
8
|
+
import type { RspackPluginInstance } from 'unplugin'
|
|
9
|
+
import { unpluginFactory } from './index'
|
|
10
|
+
import type { UnpluginStylexInstance } from './types'
|
|
11
|
+
|
|
12
|
+
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>
|
|
13
|
+
|
|
14
|
+
const rspackPlugin: RspackPluginType = createRspackPlugin(unpluginFactory)
|
|
3
15
|
|
|
4
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Rsapck plugin
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* import stylexPlugin from 'unplugin-stylex/rspack'
|
|
22
|
+
*
|
|
23
|
+
* module.exports = {
|
|
24
|
+
* plugins: [
|
|
25
|
+
* stylexPlugin(),
|
|
26
|
+
* ],
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export default rspackPlugin
|
package/src/types.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import type { FilterPattern } from '@rollup/pluginutils'
|
|
2
|
-
|
|
3
1
|
export type BabelConfig = {
|
|
4
2
|
plugins: unknown[]
|
|
5
3
|
presets: unknown[]
|
|
6
4
|
babelrc: boolean
|
|
7
5
|
}
|
|
8
6
|
|
|
9
|
-
type StylexOptions = {
|
|
7
|
+
export type StylexOptions = {
|
|
10
8
|
filename?: string
|
|
11
9
|
stylexImports?: string[]
|
|
12
10
|
classNamePrefix?: string
|
|
13
11
|
useCSSLayers?: boolean
|
|
14
12
|
unstable_moduleResolution?: {
|
|
15
|
-
type:
|
|
13
|
+
type: 'commonjs' | 'haste'
|
|
16
14
|
rootDir: string
|
|
17
15
|
}
|
|
18
16
|
babelConfig?: BabelConfig
|
|
17
|
+
runtimeInjection: boolean
|
|
18
|
+
aliases?: string[]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type UnpluginStylexOptions = {
|
|
22
|
+
compiler?: string
|
|
22
23
|
dev?: boolean
|
|
23
|
-
|
|
24
|
-
exclude?: FilterPattern
|
|
25
|
-
enforce?: "post" | "pre"
|
|
24
|
+
enforce?: 'post' | 'pre'
|
|
26
25
|
stylex?: StylexOptions
|
|
27
26
|
}
|
|
27
|
+
|
|
28
|
+
export type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T
|
package/src/vite.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This entry file is for Vite plugin.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import { createVitePlugin } from 'unplugin'
|
|
2
|
-
import {
|
|
8
|
+
import type { VitePlugin } from 'unplugin'
|
|
9
|
+
import { unpluginFactory } from './index'
|
|
10
|
+
import type { UnpluginStylexInstance } from './types'
|
|
11
|
+
|
|
12
|
+
const vitePlugin: UnpluginStylexInstance<VitePlugin | VitePlugin[]> = createVitePlugin(unpluginFactory)
|
|
3
13
|
|
|
4
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Vite example
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* import { defineConfig } from 'vite'
|
|
20
|
+
* import stylexPlugin from 'unplugin-stylex/vite'
|
|
21
|
+
*
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* plugins: [
|
|
24
|
+
* stylexPlugin(),
|
|
25
|
+
* ],
|
|
26
|
+
* })
|
|
27
|
+
*/
|
|
28
|
+
export default vitePlugin
|
package/src/webpack.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This entry file is for Webpack plugin.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import { isDevelopment } from './core/constants'
|
|
8
|
+
import type { UnpluginStylexOptions } from './types'
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Note: Current, please use @stylexjs/webpack-plugin
|
|
12
|
+
*/
|
|
13
|
+
export default (options?: UnpluginStylexOptions) => {
|
|
4
14
|
if (isDevelopment || options?.dev) {
|
|
5
|
-
throw new Error(
|
|
15
|
+
throw new Error('If you want to use this plugin through webpack, please use "@stylexjs/webpack-plugin" instead')
|
|
6
16
|
}
|
|
7
17
|
}
|
package/typos.toml
ADDED
package/vitest.config.ts
CHANGED
package/dist/chunk-D3OQCQYP.cjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkN4Z3Z2PUcjs = require('./chunk-N4Z3Z2PU.cjs');
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
var _pluginutils = require('@rollup/pluginutils');
|
|
8
|
-
var _babelplugin = require('@stylexjs/babel-plugin'); var _babelplugin2 = _interopRequireDefault(_babelplugin);
|
|
9
|
-
var _unplugin = require('unplugin');
|
|
10
|
-
|
|
11
|
-
// src/core/utils.ts
|
|
12
|
-
function getOptions(options = {}) {
|
|
13
|
-
const stylex = options.stylex || {};
|
|
14
|
-
return {
|
|
15
|
-
...options,
|
|
16
|
-
dev: options.dev || _chunkN4Z3Z2PUcjs.isDevelopment,
|
|
17
|
-
include: options.include || [/\.[jt]sx?$/],
|
|
18
|
-
exclude: options.exclude || [/node_modules/, /\.git/],
|
|
19
|
-
enforce: options.enforce || "pre",
|
|
20
|
-
stylex: {
|
|
21
|
-
...stylex,
|
|
22
|
-
filename: stylex.filename || "stylex.css",
|
|
23
|
-
stylexImports: stylex.stylexImports || ["stylex", "@stylexjs/stylex"],
|
|
24
|
-
useCSSLayers: stylex.useCSSLayers || false,
|
|
25
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
|
|
26
|
-
babelConfig: {
|
|
27
|
-
babelrc: (stylex.babelConfig || {}).babelrc || false,
|
|
28
|
-
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
29
|
-
presets: (stylex.babelConfig || {}).presets || []
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/core/transformer.ts
|
|
36
|
-
var _promises = require('fs/promises'); var fs = _interopRequireWildcard(_promises);
|
|
37
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
38
|
-
var _core = require('@babel/core');
|
|
39
|
-
var _pluginsyntaxflow = require('@babel/plugin-syntax-flow'); var _pluginsyntaxflow2 = _interopRequireDefault(_pluginsyntaxflow);
|
|
40
|
-
var _pluginsyntaxjsx = require('@babel/plugin-syntax-jsx'); var _pluginsyntaxjsx2 = _interopRequireDefault(_pluginsyntaxjsx);
|
|
41
|
-
var _pluginsyntaxtypescript = require('@babel/plugin-syntax-typescript'); var _pluginsyntaxtypescript2 = _interopRequireDefault(_pluginsyntaxtypescript);
|
|
42
|
-
|
|
43
|
-
async function transformer(context) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
const { id, source, options } = context;
|
|
46
|
-
const stylex = options.stylex;
|
|
47
|
-
const extname2 = path.extname(id);
|
|
48
|
-
const stylexRules = {};
|
|
49
|
-
if ((_b = (_a = stylex.stylexImports) == null ? void 0 : _a.some) == null ? void 0 : _b.call(_a, (importName) => source.includes(importName))) {
|
|
50
|
-
const originSource = stylex.babelConfig.babelrc ? await fs.readFile(id, "utf-8") : source;
|
|
51
|
-
const { code, map, metadata } = await _core.transformAsync.call(void 0,
|
|
52
|
-
originSource,
|
|
53
|
-
{
|
|
54
|
-
babelrc: stylex.babelConfig.babelrc,
|
|
55
|
-
filename: id,
|
|
56
|
-
plugins: [
|
|
57
|
-
...stylex.babelConfig.plugins || [],
|
|
58
|
-
extname2 === ".ts" ? _pluginsyntaxtypescript2.default : extname2 === ".tsx" ? [_pluginsyntaxtypescript2.default, { isTSX: true }] : _pluginsyntaxflow2.default,
|
|
59
|
-
_pluginsyntaxjsx2.default,
|
|
60
|
-
[
|
|
61
|
-
_babelplugin2.default,
|
|
62
|
-
{
|
|
63
|
-
dev: options.dev,
|
|
64
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
65
|
-
importSources: stylex.stylexImports,
|
|
66
|
-
...stylex
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
],
|
|
70
|
-
presets: stylex.babelConfig.presets
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
74
|
-
stylexRules[id] = metadata.stylex;
|
|
75
|
-
}
|
|
76
|
-
if (!stylex.babelConfig.babelrc) {
|
|
77
|
-
return { code, map, stylexRules };
|
|
78
|
-
}
|
|
79
|
-
return { code, stylexRules };
|
|
80
|
-
}
|
|
81
|
-
return { code: source };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/index.ts
|
|
85
|
-
var unpluginFactory = (rawOptions = {}) => {
|
|
86
|
-
const options = getOptions(rawOptions);
|
|
87
|
-
const filter = _pluginutils.createFilter.call(void 0, options.include, options.exclude);
|
|
88
|
-
const stylexRules = {};
|
|
89
|
-
let viteBuildConfig = null;
|
|
90
|
-
return {
|
|
91
|
-
name: _chunkN4Z3Z2PUcjs.PLUGIN_NAME,
|
|
92
|
-
enforce: options.enforce,
|
|
93
|
-
transformInclude(id) {
|
|
94
|
-
return filter(id);
|
|
95
|
-
},
|
|
96
|
-
async transform(source, id) {
|
|
97
|
-
const context = {
|
|
98
|
-
pluginContext: this,
|
|
99
|
-
options,
|
|
100
|
-
source,
|
|
101
|
-
id
|
|
102
|
-
};
|
|
103
|
-
try {
|
|
104
|
-
const result = await transformer(context);
|
|
105
|
-
if (result.stylexRules && result.stylexRules[id]) {
|
|
106
|
-
stylexRules[id] = result.stylexRules[id];
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.error(error);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
buildEnd() {
|
|
114
|
-
const rules = Object.values(stylexRules).flat();
|
|
115
|
-
if (rules.length === 0)
|
|
116
|
-
return;
|
|
117
|
-
const collectedCSS = _babelplugin2.default.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
118
|
-
const fileName = options.stylex.filename;
|
|
119
|
-
this.emitFile({
|
|
120
|
-
fileName,
|
|
121
|
-
source: collectedCSS,
|
|
122
|
-
type: "asset"
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
vite: {
|
|
126
|
-
config(config) {
|
|
127
|
-
viteBuildConfig = config.build;
|
|
128
|
-
},
|
|
129
|
-
buildEnd() {
|
|
130
|
-
var _a;
|
|
131
|
-
const rules = Object.values(stylexRules).flat();
|
|
132
|
-
if (!viteBuildConfig || rules.length === 0)
|
|
133
|
-
return;
|
|
134
|
-
const collectedCSS = _babelplugin2.default.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
135
|
-
const fileName = `${_nullishCoalesce(((_a = viteBuildConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets"))}/${options.stylex.filename}`;
|
|
136
|
-
this.emitFile({
|
|
137
|
-
fileName,
|
|
138
|
-
source: collectedCSS,
|
|
139
|
-
type: "asset"
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
var unplugin = _unplugin.createUnplugin.call(void 0, unpluginFactory);
|
|
146
|
-
var src_default = unplugin;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
exports.unpluginFactory = unpluginFactory; exports.unplugin = unplugin; exports.src_default = src_default;
|
package/dist/chunk-XQ5JPTTJ.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PLUGIN_NAME,
|
|
3
|
-
isDevelopment
|
|
4
|
-
} from "./chunk-36ARBXVP.js";
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
8
|
-
import stylexBabelPlugin2 from "@stylexjs/babel-plugin";
|
|
9
|
-
import { createUnplugin } from "unplugin";
|
|
10
|
-
|
|
11
|
-
// src/core/utils.ts
|
|
12
|
-
function getOptions(options = {}) {
|
|
13
|
-
const stylex = options.stylex || {};
|
|
14
|
-
return {
|
|
15
|
-
...options,
|
|
16
|
-
dev: options.dev || isDevelopment,
|
|
17
|
-
include: options.include || [/\.[jt]sx?$/],
|
|
18
|
-
exclude: options.exclude || [/node_modules/, /\.git/],
|
|
19
|
-
enforce: options.enforce || "pre",
|
|
20
|
-
stylex: {
|
|
21
|
-
...stylex,
|
|
22
|
-
filename: stylex.filename || "stylex.css",
|
|
23
|
-
stylexImports: stylex.stylexImports || ["stylex", "@stylexjs/stylex"],
|
|
24
|
-
useCSSLayers: stylex.useCSSLayers || false,
|
|
25
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
|
|
26
|
-
babelConfig: {
|
|
27
|
-
babelrc: (stylex.babelConfig || {}).babelrc || false,
|
|
28
|
-
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
29
|
-
presets: (stylex.babelConfig || {}).presets || []
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/core/transformer.ts
|
|
36
|
-
import * as fs from "fs/promises";
|
|
37
|
-
import * as path from "path";
|
|
38
|
-
import { transformAsync } from "@babel/core";
|
|
39
|
-
import flowSyntaxPlugin from "@babel/plugin-syntax-flow";
|
|
40
|
-
import jsxSyntaxPlugin from "@babel/plugin-syntax-jsx";
|
|
41
|
-
import typescriptSyntaxPlugin from "@babel/plugin-syntax-typescript";
|
|
42
|
-
import stylexBabelPlugin from "@stylexjs/babel-plugin";
|
|
43
|
-
async function transformer(context) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
const { id, source, options } = context;
|
|
46
|
-
const stylex = options.stylex;
|
|
47
|
-
const extname2 = path.extname(id);
|
|
48
|
-
const stylexRules = {};
|
|
49
|
-
if ((_b = (_a = stylex.stylexImports) == null ? void 0 : _a.some) == null ? void 0 : _b.call(_a, (importName) => source.includes(importName))) {
|
|
50
|
-
const originSource = stylex.babelConfig.babelrc ? await fs.readFile(id, "utf-8") : source;
|
|
51
|
-
const { code, map, metadata } = await transformAsync(
|
|
52
|
-
originSource,
|
|
53
|
-
{
|
|
54
|
-
babelrc: stylex.babelConfig.babelrc,
|
|
55
|
-
filename: id,
|
|
56
|
-
plugins: [
|
|
57
|
-
...stylex.babelConfig.plugins || [],
|
|
58
|
-
extname2 === ".ts" ? typescriptSyntaxPlugin : extname2 === ".tsx" ? [typescriptSyntaxPlugin, { isTSX: true }] : flowSyntaxPlugin,
|
|
59
|
-
jsxSyntaxPlugin,
|
|
60
|
-
[
|
|
61
|
-
stylexBabelPlugin,
|
|
62
|
-
{
|
|
63
|
-
dev: options.dev,
|
|
64
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
65
|
-
importSources: stylex.stylexImports,
|
|
66
|
-
...stylex
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
],
|
|
70
|
-
presets: stylex.babelConfig.presets
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
74
|
-
stylexRules[id] = metadata.stylex;
|
|
75
|
-
}
|
|
76
|
-
if (!stylex.babelConfig.babelrc) {
|
|
77
|
-
return { code, map, stylexRules };
|
|
78
|
-
}
|
|
79
|
-
return { code, stylexRules };
|
|
80
|
-
}
|
|
81
|
-
return { code: source };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/index.ts
|
|
85
|
-
var unpluginFactory = (rawOptions = {}) => {
|
|
86
|
-
const options = getOptions(rawOptions);
|
|
87
|
-
const filter = createFilter(options.include, options.exclude);
|
|
88
|
-
const stylexRules = {};
|
|
89
|
-
let viteBuildConfig = null;
|
|
90
|
-
return {
|
|
91
|
-
name: PLUGIN_NAME,
|
|
92
|
-
enforce: options.enforce,
|
|
93
|
-
transformInclude(id) {
|
|
94
|
-
return filter(id);
|
|
95
|
-
},
|
|
96
|
-
async transform(source, id) {
|
|
97
|
-
const context = {
|
|
98
|
-
pluginContext: this,
|
|
99
|
-
options,
|
|
100
|
-
source,
|
|
101
|
-
id
|
|
102
|
-
};
|
|
103
|
-
try {
|
|
104
|
-
const result = await transformer(context);
|
|
105
|
-
if (result.stylexRules && result.stylexRules[id]) {
|
|
106
|
-
stylexRules[id] = result.stylexRules[id];
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.error(error);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
buildEnd() {
|
|
114
|
-
const rules = Object.values(stylexRules).flat();
|
|
115
|
-
if (rules.length === 0)
|
|
116
|
-
return;
|
|
117
|
-
const collectedCSS = stylexBabelPlugin2.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
118
|
-
const fileName = options.stylex.filename;
|
|
119
|
-
this.emitFile({
|
|
120
|
-
fileName,
|
|
121
|
-
source: collectedCSS,
|
|
122
|
-
type: "asset"
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
vite: {
|
|
126
|
-
config(config) {
|
|
127
|
-
viteBuildConfig = config.build;
|
|
128
|
-
},
|
|
129
|
-
buildEnd() {
|
|
130
|
-
var _a;
|
|
131
|
-
const rules = Object.values(stylexRules).flat();
|
|
132
|
-
if (!viteBuildConfig || rules.length === 0)
|
|
133
|
-
return;
|
|
134
|
-
const collectedCSS = stylexBabelPlugin2.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
135
|
-
const fileName = `${((_a = viteBuildConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
|
|
136
|
-
this.emitFile({
|
|
137
|
-
fileName,
|
|
138
|
-
source: collectedCSS,
|
|
139
|
-
type: "asset"
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
var unplugin = createUnplugin(unpluginFactory);
|
|
146
|
-
var src_default = unplugin;
|
|
147
|
-
|
|
148
|
-
export {
|
|
149
|
-
unpluginFactory,
|
|
150
|
-
unplugin,
|
|
151
|
-
src_default
|
|
152
|
-
};
|