@vanilla-extract/vite-plugin 5.0.0-update-vite-20250122231739 → 5.0.0-vite-plugin-filter-20250130020334

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.
@@ -1,10 +1,20 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { IdentifierOption } from '@vanilla-extract/integration';
3
3
 
4
+ type PluginFilter = (filterProps: {
5
+ /** The name of the plugin */
6
+ name: string;
7
+ /**
8
+ * The `mode` vite is running in.
9
+ * @see https://vite.dev/guide/env-and-mode.html#modes
10
+ */
11
+ mode: string;
12
+ }) => boolean;
4
13
  interface Options {
5
14
  identifiers?: IdentifierOption;
15
+ unstable_pluginFilter?: PluginFilter;
6
16
  unstable_mode?: 'transform' | 'emitCss';
7
17
  }
8
- declare function vanillaExtractPlugin({ identifiers, unstable_mode: mode, }?: Options): Plugin;
18
+ declare function vanillaExtractPlugin({ identifiers, unstable_pluginFilter: pluginFilter, unstable_mode: mode, }?: Options): Plugin;
9
19
 
10
20
  export { vanillaExtractPlugin };
@@ -3,39 +3,42 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
+ var compiler = require('@vanilla-extract/compiler');
6
7
  var integration = require('@vanilla-extract/integration');
7
8
 
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
10
 
10
11
  var path__default = /*#__PURE__*/_interopDefault(path);
11
12
 
13
+ const PLUGIN_NAME = 'vite-plugin-vanilla-extract';
12
14
  const virtualExtCss = '.vanilla.css';
13
15
  const isVirtualId = id => id.endsWith(virtualExtCss);
14
16
  const fileIdToVirtualId = id => `${id}${virtualExtCss}`;
15
17
  const virtualIdToFileId = virtualId => virtualId.slice(0, -virtualExtCss.length);
16
- const removeIncompatiblePlugins = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
17
- // Prevent an infinite loop where the compiler creates a new instance of the plugin,
18
- // which creates a new compiler, which creates a new instance of the plugin, etc.
19
- plugin.name !== 'vanilla-extract' &&
20
- // Skip Remix because it throws an error if it's not loaded with a config file.
21
- // If it _is_ loaded with a config file, it will create an infinite loop because it
22
- // also has a child compiler which uses the same mechanism to load the config file.
23
- // https://github.com/remix-run/remix/pull/7990#issuecomment-1809356626
24
- // Additionally, some internal Remix plugins rely on a `ctx` object to be initialized by
25
- // the main Remix plugin, and may not function correctly without it. To address this, we
26
- // filter out all Remix-related plugins.
27
- !plugin.name.startsWith('remix') &&
28
- // As React-Router plugin works the same as Remix plugin, also ignore it.
29
- !plugin.name.startsWith('react-router');
18
+ const isPluginObject = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin;
19
+ // Plugins that we know are compatible with the `vite-node` compiler
20
+ // and don't need to be filtered out.
21
+ const COMPATIBLE_PLUGINS = ['vite-tsconfig-paths'];
22
+ const defaultPluginFilter = ({
23
+ name
24
+ }) => COMPATIBLE_PLUGINS.includes(name);
25
+ const withUserPluginFilter = ({
26
+ mode,
27
+ pluginFilter
28
+ }) => plugin => pluginFilter({
29
+ name: plugin.name,
30
+ mode
31
+ });
30
32
  function vanillaExtractPlugin({
31
33
  identifiers,
34
+ unstable_pluginFilter: pluginFilter = defaultPluginFilter,
32
35
  unstable_mode: mode = 'emitCss'
33
36
  } = {}) {
34
37
  let config;
35
38
  let configEnv;
36
39
  let server;
37
40
  let packageName;
38
- let compiler;
41
+ let compiler$1;
39
42
  const vitePromise = import('vite');
40
43
  const getIdentOption = () => identifiers ?? (config.mode === 'production' ? 'short' : 'debug');
41
44
  const getAbsoluteId = filePath => {
@@ -67,7 +70,7 @@ function vanillaExtractPlugin({
67
70
  }
68
71
  }
69
72
  return {
70
- name: 'vanilla-extract',
73
+ name: PLUGIN_NAME,
71
74
  configureServer(_server) {
72
75
  server = _server;
73
76
  },
@@ -85,7 +88,7 @@ function vanillaExtractPlugin({
85
88
  },
86
89
  async buildStart() {
87
90
  // Ensure we re-use the compiler instance between builds, e.g. in watch mode
88
- if (mode !== 'transform' && !compiler) {
91
+ if (mode !== 'transform' && !compiler$1) {
89
92
  var _configForViteCompile;
90
93
  const {
91
94
  loadConfigFromFile
@@ -107,9 +110,12 @@ function vanillaExtractPlugin({
107
110
  }
108
111
  const viteConfig = {
109
112
  ...configForViteCompiler,
110
- plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(removeIncompatiblePlugins)
113
+ plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(isPluginObject).filter(withUserPluginFilter({
114
+ mode: config.mode,
115
+ pluginFilter
116
+ }))
111
117
  };
112
- compiler = integration.createCompiler({
118
+ compiler$1 = compiler.createCompiler({
113
119
  root: config.root,
114
120
  identifiers: getIdentOption(),
115
121
  cssImportSpecifier: fileIdToVirtualId,
@@ -122,12 +128,12 @@ function vanillaExtractPlugin({
122
128
  // Instead, we close it when the watcher is closed via the closeWatcher hook.
123
129
  if (!config.build.watch) {
124
130
  var _compiler;
125
- (_compiler = compiler) === null || _compiler === void 0 || _compiler.close();
131
+ (_compiler = compiler$1) === null || _compiler === void 0 || _compiler.close();
126
132
  }
127
133
  },
128
134
  closeWatcher() {
129
135
  var _compiler2;
130
- return (_compiler2 = compiler) === null || _compiler2 === void 0 ? void 0 : _compiler2.close();
136
+ return (_compiler2 = compiler$1) === null || _compiler2 === void 0 ? void 0 : _compiler2.close();
131
137
  },
132
138
  async transform(code, id) {
133
139
  const [validId] = id.split('?');
@@ -144,12 +150,12 @@ function vanillaExtractPlugin({
144
150
  identOption
145
151
  });
146
152
  }
147
- if (compiler) {
153
+ if (compiler$1) {
148
154
  const absoluteId = getAbsoluteId(validId);
149
155
  const {
150
156
  source,
151
157
  watchFiles
152
- } = await compiler.processVanillaFile(absoluteId, {
158
+ } = await compiler$1.processVanillaFile(absoluteId, {
153
159
  outputCss: true
154
160
  });
155
161
  const result = {
@@ -186,18 +192,18 @@ function vanillaExtractPlugin({
186
192
  if ( // We should always have CSS for a file here.
187
193
  // The only valid scenario for a missing one is if someone had written
188
194
  // a file in their app using the .vanilla.js/.vanilla.css extension
189
- (_compiler3 = compiler) !== null && _compiler3 !== void 0 && _compiler3.getCssForFile(virtualIdToFileId(absoluteId))) {
195
+ (_compiler3 = compiler$1) !== null && _compiler3 !== void 0 && _compiler3.getCssForFile(virtualIdToFileId(absoluteId))) {
190
196
  // Keep the original query string for HMR.
191
197
  return absoluteId + (query ? `?${query}` : '');
192
198
  }
193
199
  },
194
200
  load(id) {
195
201
  const [validId] = id.split('?');
196
- if (!isVirtualId(validId) || !compiler) return;
202
+ if (!isVirtualId(validId) || !compiler$1) return;
197
203
  const absoluteId = getAbsoluteId(validId);
198
204
  const {
199
205
  css
200
- } = compiler.getCssForFile(virtualIdToFileId(absoluteId));
206
+ } = compiler$1.getCssForFile(virtualIdToFileId(absoluteId));
201
207
  return css;
202
208
  }
203
209
  };
@@ -3,39 +3,42 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
+ var compiler = require('@vanilla-extract/compiler');
6
7
  var integration = require('@vanilla-extract/integration');
7
8
 
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
10
 
10
11
  var path__default = /*#__PURE__*/_interopDefault(path);
11
12
 
13
+ const PLUGIN_NAME = 'vite-plugin-vanilla-extract';
12
14
  const virtualExtCss = '.vanilla.css';
13
15
  const isVirtualId = id => id.endsWith(virtualExtCss);
14
16
  const fileIdToVirtualId = id => `${id}${virtualExtCss}`;
15
17
  const virtualIdToFileId = virtualId => virtualId.slice(0, -virtualExtCss.length);
16
- const removeIncompatiblePlugins = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
17
- // Prevent an infinite loop where the compiler creates a new instance of the plugin,
18
- // which creates a new compiler, which creates a new instance of the plugin, etc.
19
- plugin.name !== 'vanilla-extract' &&
20
- // Skip Remix because it throws an error if it's not loaded with a config file.
21
- // If it _is_ loaded with a config file, it will create an infinite loop because it
22
- // also has a child compiler which uses the same mechanism to load the config file.
23
- // https://github.com/remix-run/remix/pull/7990#issuecomment-1809356626
24
- // Additionally, some internal Remix plugins rely on a `ctx` object to be initialized by
25
- // the main Remix plugin, and may not function correctly without it. To address this, we
26
- // filter out all Remix-related plugins.
27
- !plugin.name.startsWith('remix') &&
28
- // As React-Router plugin works the same as Remix plugin, also ignore it.
29
- !plugin.name.startsWith('react-router');
18
+ const isPluginObject = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin;
19
+ // Plugins that we know are compatible with the `vite-node` compiler
20
+ // and don't need to be filtered out.
21
+ const COMPATIBLE_PLUGINS = ['vite-tsconfig-paths'];
22
+ const defaultPluginFilter = ({
23
+ name
24
+ }) => COMPATIBLE_PLUGINS.includes(name);
25
+ const withUserPluginFilter = ({
26
+ mode,
27
+ pluginFilter
28
+ }) => plugin => pluginFilter({
29
+ name: plugin.name,
30
+ mode
31
+ });
30
32
  function vanillaExtractPlugin({
31
33
  identifiers,
34
+ unstable_pluginFilter: pluginFilter = defaultPluginFilter,
32
35
  unstable_mode: mode = 'emitCss'
33
36
  } = {}) {
34
37
  let config;
35
38
  let configEnv;
36
39
  let server;
37
40
  let packageName;
38
- let compiler;
41
+ let compiler$1;
39
42
  const vitePromise = import('vite');
40
43
  const getIdentOption = () => identifiers ?? (config.mode === 'production' ? 'short' : 'debug');
41
44
  const getAbsoluteId = filePath => {
@@ -67,7 +70,7 @@ function vanillaExtractPlugin({
67
70
  }
68
71
  }
69
72
  return {
70
- name: 'vanilla-extract',
73
+ name: PLUGIN_NAME,
71
74
  configureServer(_server) {
72
75
  server = _server;
73
76
  },
@@ -85,7 +88,7 @@ function vanillaExtractPlugin({
85
88
  },
86
89
  async buildStart() {
87
90
  // Ensure we re-use the compiler instance between builds, e.g. in watch mode
88
- if (mode !== 'transform' && !compiler) {
91
+ if (mode !== 'transform' && !compiler$1) {
89
92
  var _configForViteCompile;
90
93
  const {
91
94
  loadConfigFromFile
@@ -107,9 +110,12 @@ function vanillaExtractPlugin({
107
110
  }
108
111
  const viteConfig = {
109
112
  ...configForViteCompiler,
110
- plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(removeIncompatiblePlugins)
113
+ plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(isPluginObject).filter(withUserPluginFilter({
114
+ mode: config.mode,
115
+ pluginFilter
116
+ }))
111
117
  };
112
- compiler = integration.createCompiler({
118
+ compiler$1 = compiler.createCompiler({
113
119
  root: config.root,
114
120
  identifiers: getIdentOption(),
115
121
  cssImportSpecifier: fileIdToVirtualId,
@@ -122,12 +128,12 @@ function vanillaExtractPlugin({
122
128
  // Instead, we close it when the watcher is closed via the closeWatcher hook.
123
129
  if (!config.build.watch) {
124
130
  var _compiler;
125
- (_compiler = compiler) === null || _compiler === void 0 || _compiler.close();
131
+ (_compiler = compiler$1) === null || _compiler === void 0 || _compiler.close();
126
132
  }
127
133
  },
128
134
  closeWatcher() {
129
135
  var _compiler2;
130
- return (_compiler2 = compiler) === null || _compiler2 === void 0 ? void 0 : _compiler2.close();
136
+ return (_compiler2 = compiler$1) === null || _compiler2 === void 0 ? void 0 : _compiler2.close();
131
137
  },
132
138
  async transform(code, id) {
133
139
  const [validId] = id.split('?');
@@ -144,12 +150,12 @@ function vanillaExtractPlugin({
144
150
  identOption
145
151
  });
146
152
  }
147
- if (compiler) {
153
+ if (compiler$1) {
148
154
  const absoluteId = getAbsoluteId(validId);
149
155
  const {
150
156
  source,
151
157
  watchFiles
152
- } = await compiler.processVanillaFile(absoluteId, {
158
+ } = await compiler$1.processVanillaFile(absoluteId, {
153
159
  outputCss: true
154
160
  });
155
161
  const result = {
@@ -186,18 +192,18 @@ function vanillaExtractPlugin({
186
192
  if ( // We should always have CSS for a file here.
187
193
  // The only valid scenario for a missing one is if someone had written
188
194
  // a file in their app using the .vanilla.js/.vanilla.css extension
189
- (_compiler3 = compiler) !== null && _compiler3 !== void 0 && _compiler3.getCssForFile(virtualIdToFileId(absoluteId))) {
195
+ (_compiler3 = compiler$1) !== null && _compiler3 !== void 0 && _compiler3.getCssForFile(virtualIdToFileId(absoluteId))) {
190
196
  // Keep the original query string for HMR.
191
197
  return absoluteId + (query ? `?${query}` : '');
192
198
  }
193
199
  },
194
200
  load(id) {
195
201
  const [validId] = id.split('?');
196
- if (!isVirtualId(validId) || !compiler) return;
202
+ if (!isVirtualId(validId) || !compiler$1) return;
197
203
  const absoluteId = getAbsoluteId(validId);
198
204
  const {
199
205
  css
200
- } = compiler.getCssForFile(virtualIdToFileId(absoluteId));
206
+ } = compiler$1.getCssForFile(virtualIdToFileId(absoluteId));
201
207
  return css;
202
208
  }
203
209
  };
@@ -1,26 +1,29 @@
1
1
  import path from 'path';
2
- import { getPackageInfo, createCompiler, cssFileFilter, transform, normalizePath } from '@vanilla-extract/integration';
2
+ import { createCompiler } from '@vanilla-extract/compiler';
3
+ import { getPackageInfo, cssFileFilter, transform, normalizePath } from '@vanilla-extract/integration';
3
4
 
5
+ const PLUGIN_NAME = 'vite-plugin-vanilla-extract';
4
6
  const virtualExtCss = '.vanilla.css';
5
7
  const isVirtualId = id => id.endsWith(virtualExtCss);
6
8
  const fileIdToVirtualId = id => `${id}${virtualExtCss}`;
7
9
  const virtualIdToFileId = virtualId => virtualId.slice(0, -virtualExtCss.length);
8
- const removeIncompatiblePlugins = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
9
- // Prevent an infinite loop where the compiler creates a new instance of the plugin,
10
- // which creates a new compiler, which creates a new instance of the plugin, etc.
11
- plugin.name !== 'vanilla-extract' &&
12
- // Skip Remix because it throws an error if it's not loaded with a config file.
13
- // If it _is_ loaded with a config file, it will create an infinite loop because it
14
- // also has a child compiler which uses the same mechanism to load the config file.
15
- // https://github.com/remix-run/remix/pull/7990#issuecomment-1809356626
16
- // Additionally, some internal Remix plugins rely on a `ctx` object to be initialized by
17
- // the main Remix plugin, and may not function correctly without it. To address this, we
18
- // filter out all Remix-related plugins.
19
- !plugin.name.startsWith('remix') &&
20
- // As React-Router plugin works the same as Remix plugin, also ignore it.
21
- !plugin.name.startsWith('react-router');
10
+ const isPluginObject = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin;
11
+ // Plugins that we know are compatible with the `vite-node` compiler
12
+ // and don't need to be filtered out.
13
+ const COMPATIBLE_PLUGINS = ['vite-tsconfig-paths'];
14
+ const defaultPluginFilter = ({
15
+ name
16
+ }) => COMPATIBLE_PLUGINS.includes(name);
17
+ const withUserPluginFilter = ({
18
+ mode,
19
+ pluginFilter
20
+ }) => plugin => pluginFilter({
21
+ name: plugin.name,
22
+ mode
23
+ });
22
24
  function vanillaExtractPlugin({
23
25
  identifiers,
26
+ unstable_pluginFilter: pluginFilter = defaultPluginFilter,
24
27
  unstable_mode: mode = 'emitCss'
25
28
  } = {}) {
26
29
  let config;
@@ -59,7 +62,7 @@ function vanillaExtractPlugin({
59
62
  }
60
63
  }
61
64
  return {
62
- name: 'vanilla-extract',
65
+ name: PLUGIN_NAME,
63
66
  configureServer(_server) {
64
67
  server = _server;
65
68
  },
@@ -99,7 +102,10 @@ function vanillaExtractPlugin({
99
102
  }
100
103
  const viteConfig = {
101
104
  ...configForViteCompiler,
102
- plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(removeIncompatiblePlugins)
105
+ plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(isPluginObject).filter(withUserPluginFilter({
106
+ mode: config.mode,
107
+ pluginFilter
108
+ }))
103
109
  };
104
110
  compiler = createCompiler({
105
111
  root: config.root,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanilla-extract/vite-plugin",
3
- "version": "5.0.0-update-vite-20250122231739",
3
+ "version": "5.0.0-vite-plugin-filter-20250130020334",
4
4
  "description": "Zero-runtime Stylesheets-in-TypeScript",
5
5
  "main": "dist/vanilla-extract-vite-plugin.cjs.js",
6
6
  "module": "dist/vanilla-extract-vite-plugin.esm.js",
@@ -16,10 +16,11 @@
16
16
  "author": "SEEK",
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@vanilla-extract/integration": "^7.1.13-update-vite-20250122231739"
19
+ "@vanilla-extract/compiler": "^0.1.1-vite-plugin-filter-20250130020334",
20
+ "@vanilla-extract/integration": "^8.0.0"
20
21
  },
21
22
  "devDependencies": {
22
- "vite": "^6.0.10"
23
+ "vite": "^5.0.0 || ^6.0.0"
23
24
  },
24
25
  "peerDependencies": {
25
26
  "vite": "^5.0.0 || ^6.0.0"