@vanilla-extract/vite-plugin 5.0.0-update-vite-20250122230431 → 5.0.0-vite-plugin-filter-20250129023708

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 };
@@ -9,26 +9,28 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
9
9
 
10
10
  var path__default = /*#__PURE__*/_interopDefault(path);
11
11
 
12
+ const PLUGIN_NAME = 'vite-plugin-vanilla-extract';
12
13
  const virtualExtCss = '.vanilla.css';
13
14
  const isVirtualId = id => id.endsWith(virtualExtCss);
14
15
  const fileIdToVirtualId = id => `${id}${virtualExtCss}`;
15
16
  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');
17
+ const isPluginObject = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin;
18
+ // Plugins that we know are compatible with the `vite-node` compiler
19
+ // and don't need to be filtered out.
20
+ const COMPATIBLE_PLUGINS = ['vite-tsconfig-paths'];
21
+ const defaultPluginFilter = ({
22
+ name
23
+ }) => COMPATIBLE_PLUGINS.includes(name);
24
+ const withUserPluginFilter = ({
25
+ mode,
26
+ pluginFilter
27
+ }) => plugin => pluginFilter({
28
+ name: plugin.name,
29
+ mode
30
+ });
30
31
  function vanillaExtractPlugin({
31
32
  identifiers,
33
+ unstable_pluginFilter: pluginFilter = defaultPluginFilter,
32
34
  unstable_mode: mode = 'emitCss'
33
35
  } = {}) {
34
36
  let config;
@@ -67,7 +69,7 @@ function vanillaExtractPlugin({
67
69
  }
68
70
  }
69
71
  return {
70
- name: 'vanilla-extract',
72
+ name: PLUGIN_NAME,
71
73
  configureServer(_server) {
72
74
  server = _server;
73
75
  },
@@ -107,7 +109,10 @@ function vanillaExtractPlugin({
107
109
  }
108
110
  const viteConfig = {
109
111
  ...configForViteCompiler,
110
- plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(removeIncompatiblePlugins)
112
+ plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(isPluginObject).filter(withUserPluginFilter({
113
+ mode: config.mode,
114
+ pluginFilter
115
+ }))
111
116
  };
112
117
  compiler = integration.createCompiler({
113
118
  root: config.root,
@@ -9,26 +9,28 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
9
9
 
10
10
  var path__default = /*#__PURE__*/_interopDefault(path);
11
11
 
12
+ const PLUGIN_NAME = 'vite-plugin-vanilla-extract';
12
13
  const virtualExtCss = '.vanilla.css';
13
14
  const isVirtualId = id => id.endsWith(virtualExtCss);
14
15
  const fileIdToVirtualId = id => `${id}${virtualExtCss}`;
15
16
  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');
17
+ const isPluginObject = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin;
18
+ // Plugins that we know are compatible with the `vite-node` compiler
19
+ // and don't need to be filtered out.
20
+ const COMPATIBLE_PLUGINS = ['vite-tsconfig-paths'];
21
+ const defaultPluginFilter = ({
22
+ name
23
+ }) => COMPATIBLE_PLUGINS.includes(name);
24
+ const withUserPluginFilter = ({
25
+ mode,
26
+ pluginFilter
27
+ }) => plugin => pluginFilter({
28
+ name: plugin.name,
29
+ mode
30
+ });
30
31
  function vanillaExtractPlugin({
31
32
  identifiers,
33
+ unstable_pluginFilter: pluginFilter = defaultPluginFilter,
32
34
  unstable_mode: mode = 'emitCss'
33
35
  } = {}) {
34
36
  let config;
@@ -67,7 +69,7 @@ function vanillaExtractPlugin({
67
69
  }
68
70
  }
69
71
  return {
70
- name: 'vanilla-extract',
72
+ name: PLUGIN_NAME,
71
73
  configureServer(_server) {
72
74
  server = _server;
73
75
  },
@@ -107,7 +109,10 @@ function vanillaExtractPlugin({
107
109
  }
108
110
  const viteConfig = {
109
111
  ...configForViteCompiler,
110
- plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(removeIncompatiblePlugins)
112
+ plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(isPluginObject).filter(withUserPluginFilter({
113
+ mode: config.mode,
114
+ pluginFilter
115
+ }))
111
116
  };
112
117
  compiler = integration.createCompiler({
113
118
  root: config.root,
@@ -1,26 +1,28 @@
1
1
  import path from 'path';
2
2
  import { getPackageInfo, createCompiler, cssFileFilter, transform, normalizePath } from '@vanilla-extract/integration';
3
3
 
4
+ const PLUGIN_NAME = 'vite-plugin-vanilla-extract';
4
5
  const virtualExtCss = '.vanilla.css';
5
6
  const isVirtualId = id => id.endsWith(virtualExtCss);
6
7
  const fileIdToVirtualId = id => `${id}${virtualExtCss}`;
7
8
  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');
9
+ const isPluginObject = plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin;
10
+ // Plugins that we know are compatible with the `vite-node` compiler
11
+ // and don't need to be filtered out.
12
+ const COMPATIBLE_PLUGINS = ['vite-tsconfig-paths'];
13
+ const defaultPluginFilter = ({
14
+ name
15
+ }) => COMPATIBLE_PLUGINS.includes(name);
16
+ const withUserPluginFilter = ({
17
+ mode,
18
+ pluginFilter
19
+ }) => plugin => pluginFilter({
20
+ name: plugin.name,
21
+ mode
22
+ });
22
23
  function vanillaExtractPlugin({
23
24
  identifiers,
25
+ unstable_pluginFilter: pluginFilter = defaultPluginFilter,
24
26
  unstable_mode: mode = 'emitCss'
25
27
  } = {}) {
26
28
  let config;
@@ -59,7 +61,7 @@ function vanillaExtractPlugin({
59
61
  }
60
62
  }
61
63
  return {
62
- name: 'vanilla-extract',
64
+ name: PLUGIN_NAME,
63
65
  configureServer(_server) {
64
66
  server = _server;
65
67
  },
@@ -99,7 +101,10 @@ function vanillaExtractPlugin({
99
101
  }
100
102
  const viteConfig = {
101
103
  ...configForViteCompiler,
102
- plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(removeIncompatiblePlugins)
104
+ plugins: (_configForViteCompile = configForViteCompiler) === null || _configForViteCompile === void 0 || (_configForViteCompile = _configForViteCompile.plugins) === null || _configForViteCompile === void 0 ? void 0 : _configForViteCompile.flat().filter(isPluginObject).filter(withUserPluginFilter({
105
+ mode: config.mode,
106
+ pluginFilter
107
+ }))
103
108
  };
104
109
  compiler = createCompiler({
105
110
  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-20250122230431",
3
+ "version": "5.0.0-vite-plugin-filter-20250129023708",
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,12 +16,12 @@
16
16
  "author": "SEEK",
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@vanilla-extract/integration": "^7.1.13-update-vite-20250122230431"
19
+ "@vanilla-extract/integration": "^7.1.13-vite-plugin-filter-20250129023708"
20
20
  },
21
21
  "devDependencies": {
22
- "vite": "^6.0.10"
22
+ "vite": "^5.0.11"
23
23
  },
24
24
  "peerDependencies": {
25
- "vite": "^5.0.0 || ^6.0.0"
25
+ "vite": "^4.0.3 || ^5.0.0"
26
26
  }
27
27
  }