@vanilla-extract/vite-plugin 0.0.0-dts-bundle-202282944525

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 SEEK
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,95 @@
1
+ # 🧁 vanilla-extract
2
+
3
+ **Zero-runtime Stylesheets-in-TypeScript.**
4
+
5
+ Write your styles in TypeScript (or JavaScript) with locally scoped class names and CSS Variables, then generate static CSS files at build time.
6
+
7
+ Basically, it’s [β€œCSS Modules](https://github.com/css-modules/css-modules)-in-TypeScript” but with scoped CSS Variables + heaps more.
8
+
9
+ πŸ”₯   All styles generated at build time β€” just like [Sass](https://sass-lang.com), [Less](http://lesscss.org), etc.
10
+
11
+ ✨   Minimal abstraction over standard CSS.
12
+
13
+ πŸ¦„   Works with any front-end framework β€” or even without one.
14
+
15
+ 🌳   Locally scoped class names β€” just like [CSS Modules.](https://github.com/css-modules/css-modules)
16
+
17
+ πŸš€   Locally scoped [CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties), `@keyframes` and `@font-face` rules.
18
+
19
+ 🎨   High-level theme system with support for simultaneous themes. No globals!
20
+
21
+ πŸ›    Utils for generating variable-based `calc` expressions.
22
+
23
+ πŸ’ͺ   Type-safe styles via [CSSType.](https://github.com/frenic/csstype)
24
+
25
+ πŸƒβ€β™‚οΈ   Optional runtime version for development and testing.
26
+
27
+ πŸ™ˆ   Optional API for dynamic runtime theming.
28
+
29
+ ---
30
+
31
+ 🌐 [Check out the documentation site for setup guides, examples and API docs.](https://vanilla-extract.style)
32
+
33
+
34
+
35
+ ---
36
+
37
+ πŸ–₯   [Try it out for yourself in CodeSandbox.](https://codesandbox.io/s/github/vanilla-extract-css/vanilla-extract/tree/master/examples/webpack-react?file=/src/App.css.ts)
38
+
39
+ ---
40
+
41
+ **Write your styles in `.css.ts` files.**
42
+
43
+ ```ts
44
+ // styles.css.ts
45
+
46
+ import { createTheme, style } from '@vanilla-extract/css';
47
+
48
+ export const [themeClass, vars] = createTheme({
49
+ color: {
50
+ brand: 'blue'
51
+ },
52
+ font: {
53
+ body: 'arial'
54
+ }
55
+ });
56
+
57
+ export const exampleStyle = style({
58
+ backgroundColor: vars.color.brand,
59
+ fontFamily: vars.font.body,
60
+ color: 'white',
61
+ padding: 10
62
+ });
63
+ ```
64
+
65
+ > πŸ’‘ Once you've [configured your build tooling,](https://vanilla-extract.style/documentation/getting-started/) these `.css.ts` files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.
66
+
67
+ **Then consume them in your markup.**
68
+
69
+ ```ts
70
+ // app.ts
71
+
72
+ import { themeClass, exampleStyle } from './styles.css.ts';
73
+
74
+ document.write(`
75
+ <section class="${themeClass}">
76
+ <h1 class="${exampleStyle}">Hello world!</h1>
77
+ </section>
78
+ `);
79
+ ```
80
+
81
+ ---
82
+
83
+ Want to work at a higher level while maximising style re-use? Check out 🍨 [Sprinkles](https://vanilla-extract.style/documentation/packages/sprinkles), our official zero-runtime atomic CSS framework, built on top of vanilla-extract.
84
+
85
+ ---
86
+
87
+ ## Thanks
88
+
89
+ - [Nathan Nam Tran](https://twitter.com/naistran) for creating [css-in-js-loader](https://github.com/naistran/css-in-js-loader), which served as the initial starting point for [treat](https://seek-oss.github.io/treat), the precursor to this library.
90
+ - [Stitches](https://stitches.dev/) for getting us excited about CSS-Variables-in-JS.
91
+ - [SEEK](https://www.seek.com.au) for giving us the space to do interesting work.
92
+
93
+ ## License
94
+
95
+ MIT.
@@ -0,0 +1,10 @@
1
+ import { Plugin } from 'vite';
2
+ import { IdentifierOption, CompileOptions } from '@vanilla-extract/integration';
3
+
4
+ interface Options {
5
+ identifiers?: IdentifierOption;
6
+ esbuildOptions?: CompileOptions['esbuildOptions'];
7
+ }
8
+ declare function vanillaExtractPlugin({ identifiers, esbuildOptions, }?: Options): Plugin;
9
+
10
+ export { vanillaExtractPlugin };
@@ -0,0 +1,275 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var path = require('path');
6
+ var vite = require('vite');
7
+ var outdent = require('outdent');
8
+ var integration = require('@vanilla-extract/integration');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n["default"] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var path__default = /*#__PURE__*/_interopDefault(path);
31
+ var outdent__default = /*#__PURE__*/_interopDefault(outdent);
32
+
33
+ // Mostly copied from vite's implementation
34
+ // https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts
35
+ const resolvePostcssConfig = async config => {
36
+ var _config$css;
37
+
38
+ // inline postcss config via vite config
39
+ const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss;
40
+ const inlineOptionsIsString = typeof inlineOptions === 'string';
41
+
42
+ if (inlineOptions && !inlineOptionsIsString) {
43
+ const options = { ...inlineOptions
44
+ };
45
+ delete options.plugins;
46
+ return {
47
+ options,
48
+ plugins: inlineOptions.plugins || []
49
+ };
50
+ } else {
51
+ try {
52
+ const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
53
+ const postCssConfig = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss-load-config')); })).default({}, searchPath);
54
+ return {
55
+ options: postCssConfig.options,
56
+ // @ts-expect-error - The postcssrc options don't agree with real postcss, but it should be ok
57
+ plugins: postCssConfig.plugins
58
+ };
59
+ } catch (e) {
60
+ if (!/No PostCSS Config found/.test(e.message)) {
61
+ throw e;
62
+ }
63
+
64
+ return null;
65
+ }
66
+ }
67
+ };
68
+
69
+ const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
70
+
71
+ const virtualExtCss = '.vanilla.css';
72
+ const virtualExtJs = '.vanilla.js';
73
+ function vanillaExtractPlugin({
74
+ identifiers,
75
+ esbuildOptions
76
+ } = {}) {
77
+ let config;
78
+ let server;
79
+ let postCssConfig;
80
+ const cssMap = new Map();
81
+ let forceEmitCssInSsrBuild = !!process.env.VITE_RSC_BUILD;
82
+ let packageName;
83
+
84
+ const getAbsoluteVirtualFileId = source => vite.normalizePath(path__default["default"].join(config.root, source));
85
+
86
+ return {
87
+ name: 'vanilla-extract',
88
+ enforce: 'pre',
89
+
90
+ configureServer(_server) {
91
+ server = _server;
92
+ },
93
+
94
+ config(_userConfig, env) {
95
+ const include = env.command === 'serve' ? ['@vanilla-extract/css/injectStyles'] : [];
96
+ return {
97
+ optimizeDeps: {
98
+ include
99
+ },
100
+ ssr: {
101
+ external: ['@vanilla-extract/css', '@vanilla-extract/css/fileScope', '@vanilla-extract/css/adapter']
102
+ }
103
+ };
104
+ },
105
+
106
+ async configResolved(resolvedConfig) {
107
+ config = resolvedConfig;
108
+ packageName = integration.getPackageInfo(config.root).name;
109
+
110
+ if (config.command === 'serve') {
111
+ postCssConfig = await resolvePostcssConfig(config);
112
+ }
113
+
114
+ if (config.plugins.some(plugin => ['astro:build', 'solid-start-server'].includes(plugin.name))) {
115
+ forceEmitCssInSsrBuild = true;
116
+ }
117
+ },
118
+
119
+ resolveId(source) {
120
+ const [validId, query] = source.split('?');
121
+
122
+ if (!validId.endsWith(virtualExtCss) && !validId.endsWith(virtualExtJs)) {
123
+ return;
124
+ } // Absolute paths seem to occur often in monorepos, where files are
125
+ // imported from outside the config root.
126
+
127
+
128
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
129
+ // The only valid scenario for a missing one is if someone had written
130
+ // a file in their app using the .vanilla.js/.vanilla.css extension
131
+
132
+ if (cssMap.has(absoluteId)) {
133
+ // Keep the original query string for HMR.
134
+ return absoluteId + (query ? `?${query}` : '');
135
+ }
136
+ },
137
+
138
+ load(id) {
139
+ const [validId] = id.split('?');
140
+
141
+ if (!cssMap.has(validId)) {
142
+ return;
143
+ }
144
+
145
+ const css = cssMap.get(validId);
146
+
147
+ if (typeof css !== 'string') {
148
+ return;
149
+ }
150
+
151
+ if (validId.endsWith(virtualExtCss)) {
152
+ return css;
153
+ }
154
+
155
+ return outdent__default["default"]`
156
+ import { injectStyles } from '@vanilla-extract/css/injectStyles';
157
+
158
+ const inject = (css) => injectStyles({
159
+ fileScope: ${JSON.stringify({
160
+ filePath: validId
161
+ })},
162
+ css
163
+ });
164
+
165
+ inject(${JSON.stringify(css)});
166
+
167
+ if (import.meta.hot) {
168
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
169
+ inject(css);
170
+ });
171
+ }
172
+ `;
173
+ },
174
+
175
+ async transform(code, id, ssrParam) {
176
+ const [validId] = id.split('?');
177
+
178
+ if (!integration.cssFileFilter.test(validId)) {
179
+ return null;
180
+ }
181
+
182
+ const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug';
183
+ let ssr;
184
+
185
+ if (typeof ssrParam === 'boolean') {
186
+ ssr = ssrParam;
187
+ } else {
188
+ ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
189
+ }
190
+
191
+ if (ssr && !forceEmitCssInSsrBuild) {
192
+ return integration.transform({
193
+ source: code,
194
+ filePath: vite.normalizePath(validId),
195
+ rootPath: config.root,
196
+ packageName,
197
+ identOption
198
+ });
199
+ }
200
+
201
+ const {
202
+ source,
203
+ watchFiles
204
+ } = await integration.compile({
205
+ filePath: validId,
206
+ cwd: config.root,
207
+ esbuildOptions,
208
+ identOption
209
+ });
210
+
211
+ for (const file of watchFiles) {
212
+ // In start mode, we need to prevent the file from rewatching itself.
213
+ // If it's a `build --watch`, it needs to watch everything.
214
+ if (config.command === 'build' || file !== validId) {
215
+ this.addWatchFile(file);
216
+ }
217
+ }
218
+
219
+ const output = await integration.processVanillaFile({
220
+ source,
221
+ filePath: validId,
222
+ identOption,
223
+ serializeVirtualCssPath: async ({
224
+ fileScope,
225
+ source
226
+ }) => {
227
+ const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && forceEmitCssInSsrBuild ? virtualExtCss : virtualExtJs}`;
228
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
229
+ let cssSource = source;
230
+
231
+ if (postCssConfig) {
232
+ const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(source, { ...postCssConfig.options,
233
+ from: undefined,
234
+ map: false
235
+ });
236
+ cssSource = postCssResult.css;
237
+ }
238
+
239
+ if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
240
+ const {
241
+ moduleGraph
242
+ } = server;
243
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
244
+
245
+ if (module) {
246
+ moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
247
+
248
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
249
+ }
250
+
251
+ server.ws.send({
252
+ type: 'custom',
253
+ event: styleUpdateEvent(absoluteId),
254
+ data: cssSource
255
+ });
256
+ }
257
+
258
+ cssMap.set(absoluteId, cssSource); // We use the root relative id here to ensure file contents (content-hashes)
259
+ // are consistent across build machines
260
+
261
+ return `import "${rootRelativeId}";`;
262
+ }
263
+ });
264
+ return {
265
+ code: output,
266
+ map: {
267
+ mappings: ''
268
+ }
269
+ };
270
+ }
271
+
272
+ };
273
+ }
274
+
275
+ exports.vanillaExtractPlugin = vanillaExtractPlugin;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./vanilla-extract-vite-plugin.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./vanilla-extract-vite-plugin.cjs.dev.js");
7
+ }
@@ -0,0 +1,275 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var path = require('path');
6
+ var vite = require('vite');
7
+ var outdent = require('outdent');
8
+ var integration = require('@vanilla-extract/integration');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n["default"] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var path__default = /*#__PURE__*/_interopDefault(path);
31
+ var outdent__default = /*#__PURE__*/_interopDefault(outdent);
32
+
33
+ // Mostly copied from vite's implementation
34
+ // https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts
35
+ const resolvePostcssConfig = async config => {
36
+ var _config$css;
37
+
38
+ // inline postcss config via vite config
39
+ const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss;
40
+ const inlineOptionsIsString = typeof inlineOptions === 'string';
41
+
42
+ if (inlineOptions && !inlineOptionsIsString) {
43
+ const options = { ...inlineOptions
44
+ };
45
+ delete options.plugins;
46
+ return {
47
+ options,
48
+ plugins: inlineOptions.plugins || []
49
+ };
50
+ } else {
51
+ try {
52
+ const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
53
+ const postCssConfig = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss-load-config')); })).default({}, searchPath);
54
+ return {
55
+ options: postCssConfig.options,
56
+ // @ts-expect-error - The postcssrc options don't agree with real postcss, but it should be ok
57
+ plugins: postCssConfig.plugins
58
+ };
59
+ } catch (e) {
60
+ if (!/No PostCSS Config found/.test(e.message)) {
61
+ throw e;
62
+ }
63
+
64
+ return null;
65
+ }
66
+ }
67
+ };
68
+
69
+ const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
70
+
71
+ const virtualExtCss = '.vanilla.css';
72
+ const virtualExtJs = '.vanilla.js';
73
+ function vanillaExtractPlugin({
74
+ identifiers,
75
+ esbuildOptions
76
+ } = {}) {
77
+ let config;
78
+ let server;
79
+ let postCssConfig;
80
+ const cssMap = new Map();
81
+ let forceEmitCssInSsrBuild = !!process.env.VITE_RSC_BUILD;
82
+ let packageName;
83
+
84
+ const getAbsoluteVirtualFileId = source => vite.normalizePath(path__default["default"].join(config.root, source));
85
+
86
+ return {
87
+ name: 'vanilla-extract',
88
+ enforce: 'pre',
89
+
90
+ configureServer(_server) {
91
+ server = _server;
92
+ },
93
+
94
+ config(_userConfig, env) {
95
+ const include = env.command === 'serve' ? ['@vanilla-extract/css/injectStyles'] : [];
96
+ return {
97
+ optimizeDeps: {
98
+ include
99
+ },
100
+ ssr: {
101
+ external: ['@vanilla-extract/css', '@vanilla-extract/css/fileScope', '@vanilla-extract/css/adapter']
102
+ }
103
+ };
104
+ },
105
+
106
+ async configResolved(resolvedConfig) {
107
+ config = resolvedConfig;
108
+ packageName = integration.getPackageInfo(config.root).name;
109
+
110
+ if (config.command === 'serve') {
111
+ postCssConfig = await resolvePostcssConfig(config);
112
+ }
113
+
114
+ if (config.plugins.some(plugin => ['astro:build', 'solid-start-server'].includes(plugin.name))) {
115
+ forceEmitCssInSsrBuild = true;
116
+ }
117
+ },
118
+
119
+ resolveId(source) {
120
+ const [validId, query] = source.split('?');
121
+
122
+ if (!validId.endsWith(virtualExtCss) && !validId.endsWith(virtualExtJs)) {
123
+ return;
124
+ } // Absolute paths seem to occur often in monorepos, where files are
125
+ // imported from outside the config root.
126
+
127
+
128
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
129
+ // The only valid scenario for a missing one is if someone had written
130
+ // a file in their app using the .vanilla.js/.vanilla.css extension
131
+
132
+ if (cssMap.has(absoluteId)) {
133
+ // Keep the original query string for HMR.
134
+ return absoluteId + (query ? `?${query}` : '');
135
+ }
136
+ },
137
+
138
+ load(id) {
139
+ const [validId] = id.split('?');
140
+
141
+ if (!cssMap.has(validId)) {
142
+ return;
143
+ }
144
+
145
+ const css = cssMap.get(validId);
146
+
147
+ if (typeof css !== 'string') {
148
+ return;
149
+ }
150
+
151
+ if (validId.endsWith(virtualExtCss)) {
152
+ return css;
153
+ }
154
+
155
+ return outdent__default["default"]`
156
+ import { injectStyles } from '@vanilla-extract/css/injectStyles';
157
+
158
+ const inject = (css) => injectStyles({
159
+ fileScope: ${JSON.stringify({
160
+ filePath: validId
161
+ })},
162
+ css
163
+ });
164
+
165
+ inject(${JSON.stringify(css)});
166
+
167
+ if (import.meta.hot) {
168
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
169
+ inject(css);
170
+ });
171
+ }
172
+ `;
173
+ },
174
+
175
+ async transform(code, id, ssrParam) {
176
+ const [validId] = id.split('?');
177
+
178
+ if (!integration.cssFileFilter.test(validId)) {
179
+ return null;
180
+ }
181
+
182
+ const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug';
183
+ let ssr;
184
+
185
+ if (typeof ssrParam === 'boolean') {
186
+ ssr = ssrParam;
187
+ } else {
188
+ ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
189
+ }
190
+
191
+ if (ssr && !forceEmitCssInSsrBuild) {
192
+ return integration.transform({
193
+ source: code,
194
+ filePath: vite.normalizePath(validId),
195
+ rootPath: config.root,
196
+ packageName,
197
+ identOption
198
+ });
199
+ }
200
+
201
+ const {
202
+ source,
203
+ watchFiles
204
+ } = await integration.compile({
205
+ filePath: validId,
206
+ cwd: config.root,
207
+ esbuildOptions,
208
+ identOption
209
+ });
210
+
211
+ for (const file of watchFiles) {
212
+ // In start mode, we need to prevent the file from rewatching itself.
213
+ // If it's a `build --watch`, it needs to watch everything.
214
+ if (config.command === 'build' || file !== validId) {
215
+ this.addWatchFile(file);
216
+ }
217
+ }
218
+
219
+ const output = await integration.processVanillaFile({
220
+ source,
221
+ filePath: validId,
222
+ identOption,
223
+ serializeVirtualCssPath: async ({
224
+ fileScope,
225
+ source
226
+ }) => {
227
+ const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && forceEmitCssInSsrBuild ? virtualExtCss : virtualExtJs}`;
228
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
229
+ let cssSource = source;
230
+
231
+ if (postCssConfig) {
232
+ const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(source, { ...postCssConfig.options,
233
+ from: undefined,
234
+ map: false
235
+ });
236
+ cssSource = postCssResult.css;
237
+ }
238
+
239
+ if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
240
+ const {
241
+ moduleGraph
242
+ } = server;
243
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
244
+
245
+ if (module) {
246
+ moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
247
+
248
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
249
+ }
250
+
251
+ server.ws.send({
252
+ type: 'custom',
253
+ event: styleUpdateEvent(absoluteId),
254
+ data: cssSource
255
+ });
256
+ }
257
+
258
+ cssMap.set(absoluteId, cssSource); // We use the root relative id here to ensure file contents (content-hashes)
259
+ // are consistent across build machines
260
+
261
+ return `import "${rootRelativeId}";`;
262
+ }
263
+ });
264
+ return {
265
+ code: output,
266
+ map: {
267
+ mappings: ''
268
+ }
269
+ };
270
+ }
271
+
272
+ };
273
+ }
274
+
275
+ exports.vanillaExtractPlugin = vanillaExtractPlugin;
@@ -0,0 +1,248 @@
1
+ import path from 'path';
2
+ import { normalizePath } from 'vite';
3
+ import outdent from 'outdent';
4
+ import { getPackageInfo, cssFileFilter, transform, compile, processVanillaFile } from '@vanilla-extract/integration';
5
+
6
+ // Mostly copied from vite's implementation
7
+ // https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts
8
+ const resolvePostcssConfig = async config => {
9
+ var _config$css;
10
+
11
+ // inline postcss config via vite config
12
+ const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss;
13
+ const inlineOptionsIsString = typeof inlineOptions === 'string';
14
+
15
+ if (inlineOptions && !inlineOptionsIsString) {
16
+ const options = { ...inlineOptions
17
+ };
18
+ delete options.plugins;
19
+ return {
20
+ options,
21
+ plugins: inlineOptions.plugins || []
22
+ };
23
+ } else {
24
+ try {
25
+ const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
26
+ const postCssConfig = await (await import('postcss-load-config')).default({}, searchPath);
27
+ return {
28
+ options: postCssConfig.options,
29
+ // @ts-expect-error - The postcssrc options don't agree with real postcss, but it should be ok
30
+ plugins: postCssConfig.plugins
31
+ };
32
+ } catch (e) {
33
+ if (!/No PostCSS Config found/.test(e.message)) {
34
+ throw e;
35
+ }
36
+
37
+ return null;
38
+ }
39
+ }
40
+ };
41
+
42
+ const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
43
+
44
+ const virtualExtCss = '.vanilla.css';
45
+ const virtualExtJs = '.vanilla.js';
46
+ function vanillaExtractPlugin({
47
+ identifiers,
48
+ esbuildOptions
49
+ } = {}) {
50
+ let config;
51
+ let server;
52
+ let postCssConfig;
53
+ const cssMap = new Map();
54
+ let forceEmitCssInSsrBuild = !!process.env.VITE_RSC_BUILD;
55
+ let packageName;
56
+
57
+ const getAbsoluteVirtualFileId = source => normalizePath(path.join(config.root, source));
58
+
59
+ return {
60
+ name: 'vanilla-extract',
61
+ enforce: 'pre',
62
+
63
+ configureServer(_server) {
64
+ server = _server;
65
+ },
66
+
67
+ config(_userConfig, env) {
68
+ const include = env.command === 'serve' ? ['@vanilla-extract/css/injectStyles'] : [];
69
+ return {
70
+ optimizeDeps: {
71
+ include
72
+ },
73
+ ssr: {
74
+ external: ['@vanilla-extract/css', '@vanilla-extract/css/fileScope', '@vanilla-extract/css/adapter']
75
+ }
76
+ };
77
+ },
78
+
79
+ async configResolved(resolvedConfig) {
80
+ config = resolvedConfig;
81
+ packageName = getPackageInfo(config.root).name;
82
+
83
+ if (config.command === 'serve') {
84
+ postCssConfig = await resolvePostcssConfig(config);
85
+ }
86
+
87
+ if (config.plugins.some(plugin => ['astro:build', 'solid-start-server'].includes(plugin.name))) {
88
+ forceEmitCssInSsrBuild = true;
89
+ }
90
+ },
91
+
92
+ resolveId(source) {
93
+ const [validId, query] = source.split('?');
94
+
95
+ if (!validId.endsWith(virtualExtCss) && !validId.endsWith(virtualExtJs)) {
96
+ return;
97
+ } // Absolute paths seem to occur often in monorepos, where files are
98
+ // imported from outside the config root.
99
+
100
+
101
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
102
+ // The only valid scenario for a missing one is if someone had written
103
+ // a file in their app using the .vanilla.js/.vanilla.css extension
104
+
105
+ if (cssMap.has(absoluteId)) {
106
+ // Keep the original query string for HMR.
107
+ return absoluteId + (query ? `?${query}` : '');
108
+ }
109
+ },
110
+
111
+ load(id) {
112
+ const [validId] = id.split('?');
113
+
114
+ if (!cssMap.has(validId)) {
115
+ return;
116
+ }
117
+
118
+ const css = cssMap.get(validId);
119
+
120
+ if (typeof css !== 'string') {
121
+ return;
122
+ }
123
+
124
+ if (validId.endsWith(virtualExtCss)) {
125
+ return css;
126
+ }
127
+
128
+ return outdent`
129
+ import { injectStyles } from '@vanilla-extract/css/injectStyles';
130
+
131
+ const inject = (css) => injectStyles({
132
+ fileScope: ${JSON.stringify({
133
+ filePath: validId
134
+ })},
135
+ css
136
+ });
137
+
138
+ inject(${JSON.stringify(css)});
139
+
140
+ if (import.meta.hot) {
141
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
142
+ inject(css);
143
+ });
144
+ }
145
+ `;
146
+ },
147
+
148
+ async transform(code, id, ssrParam) {
149
+ const [validId] = id.split('?');
150
+
151
+ if (!cssFileFilter.test(validId)) {
152
+ return null;
153
+ }
154
+
155
+ const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug';
156
+ let ssr;
157
+
158
+ if (typeof ssrParam === 'boolean') {
159
+ ssr = ssrParam;
160
+ } else {
161
+ ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
162
+ }
163
+
164
+ if (ssr && !forceEmitCssInSsrBuild) {
165
+ return transform({
166
+ source: code,
167
+ filePath: normalizePath(validId),
168
+ rootPath: config.root,
169
+ packageName,
170
+ identOption
171
+ });
172
+ }
173
+
174
+ const {
175
+ source,
176
+ watchFiles
177
+ } = await compile({
178
+ filePath: validId,
179
+ cwd: config.root,
180
+ esbuildOptions,
181
+ identOption
182
+ });
183
+
184
+ for (const file of watchFiles) {
185
+ // In start mode, we need to prevent the file from rewatching itself.
186
+ // If it's a `build --watch`, it needs to watch everything.
187
+ if (config.command === 'build' || file !== validId) {
188
+ this.addWatchFile(file);
189
+ }
190
+ }
191
+
192
+ const output = await processVanillaFile({
193
+ source,
194
+ filePath: validId,
195
+ identOption,
196
+ serializeVirtualCssPath: async ({
197
+ fileScope,
198
+ source
199
+ }) => {
200
+ const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && forceEmitCssInSsrBuild ? virtualExtCss : virtualExtJs}`;
201
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
202
+ let cssSource = source;
203
+
204
+ if (postCssConfig) {
205
+ const postCssResult = await (await import('postcss')).default(postCssConfig.plugins).process(source, { ...postCssConfig.options,
206
+ from: undefined,
207
+ map: false
208
+ });
209
+ cssSource = postCssResult.css;
210
+ }
211
+
212
+ if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
213
+ const {
214
+ moduleGraph
215
+ } = server;
216
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
217
+
218
+ if (module) {
219
+ moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
220
+
221
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
222
+ }
223
+
224
+ server.ws.send({
225
+ type: 'custom',
226
+ event: styleUpdateEvent(absoluteId),
227
+ data: cssSource
228
+ });
229
+ }
230
+
231
+ cssMap.set(absoluteId, cssSource); // We use the root relative id here to ensure file contents (content-hashes)
232
+ // are consistent across build machines
233
+
234
+ return `import "${rootRelativeId}";`;
235
+ }
236
+ });
237
+ return {
238
+ code: output,
239
+ map: {
240
+ mappings: ''
241
+ }
242
+ };
243
+ }
244
+
245
+ };
246
+ }
247
+
248
+ export { vanillaExtractPlugin };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@vanilla-extract/vite-plugin",
3
+ "version": "0.0.0-dts-bundle-202282944525",
4
+ "description": "Zero-runtime Stylesheets-in-TypeScript",
5
+ "main": "dist/vanilla-extract-vite-plugin.cjs.js",
6
+ "module": "dist/vanilla-extract-vite-plugin.esm.js",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/vanilla-extract-css/vanilla-extract.git",
13
+ "directory": "packages/vite-plugin"
14
+ },
15
+ "author": "SEEK",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "@vanilla-extract/integration": "^0.0.0-dts-bundle-202282944525",
19
+ "outdent": "^0.8.0",
20
+ "postcss": "^8.3.6",
21
+ "postcss-load-config": "^3.1.0"
22
+ },
23
+ "devDependencies": {
24
+ "vite": "^2.7.0"
25
+ },
26
+ "peerDependencies": {
27
+ "vite": "^2.2.3"
28
+ }
29
+ }