@vanilla-extract/vite-plugin 4.0.3 → 4.0.5

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.
@@ -18,10 +18,11 @@ function vanillaExtractPlugin({
18
18
  unstable_mode: mode = 'emitCss'
19
19
  } = {}) {
20
20
  let config;
21
- let userConfig;
21
+ let configEnv;
22
22
  let server;
23
23
  let packageName;
24
24
  let compiler;
25
+ const vitePromise = import('vite');
25
26
  const getIdentOption = () => identifiers ?? (config.mode === 'production' ? 'short' : 'debug');
26
27
  const getAbsoluteId = filePath => {
27
28
  let resolvedId = filePath;
@@ -66,38 +67,51 @@ function vanillaExtractPlugin({
66
67
  configureServer(_server) {
67
68
  server = _server;
68
69
  },
69
- config(viteUserConfig) {
70
- userConfig = viteUserConfig;
70
+ config(_userConfig, _configEnv) {
71
+ configEnv = _configEnv;
71
72
  return {
72
73
  ssr: {
73
74
  external: ['@vanilla-extract/css', '@vanilla-extract/css/fileScope', '@vanilla-extract/css/adapter']
74
75
  }
75
76
  };
76
77
  },
77
- async configResolved(resolvedConfig) {
78
- config = resolvedConfig;
78
+ async configResolved(_resolvedConfig) {
79
+ config = _resolvedConfig;
79
80
  packageName = integration.getPackageInfo(config.root).name;
81
+ },
82
+ async buildStart() {
80
83
  if (mode !== 'transform') {
81
- var _userConfig$plugins;
84
+ var _configFile$config$pl;
85
+ const {
86
+ loadConfigFromFile
87
+ } = await vitePromise;
88
+ const configFile = await loadConfigFromFile({
89
+ command: config.command,
90
+ mode: config.mode,
91
+ isSsrBuild: configEnv.isSsrBuild
92
+ }, config.configFile);
82
93
  compiler = integration.createCompiler({
83
94
  root: config.root,
84
95
  identifiers: getIdentOption(),
85
96
  cssImportSpecifier: fileIdToVirtualId,
86
- viteResolve: config.resolve,
87
- vitePlugins: (_userConfig$plugins = userConfig.plugins) === null || _userConfig$plugins === void 0 ? void 0 : _userConfig$plugins.flat().filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
88
- // Prevent an infinite loop where the compiler creates a new instance of the plugin,
89
- // which creates a new compiler, which creates a new instance of the plugin, etc.
90
- plugin.name !== 'vanilla-extract' &&
91
- // Skip Vitest plugins
92
- plugin.name !== 'vitest' && !plugin.name.startsWith('vitest:') &&
93
- // Skip Remix because it throws an error if it's not loaded with a config file
94
- plugin.name !== 'remix')
97
+ viteConfig: {
98
+ ...(configFile === null || configFile === void 0 ? void 0 : configFile.config),
99
+ plugins: configFile === null || configFile === void 0 || (_configFile$config$pl = configFile.config.plugins) === null || _configFile$config$pl === void 0 ? void 0 : _configFile$config$pl.flat().filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
100
+ // Prevent an infinite loop where the compiler creates a new instance of the plugin,
101
+ // which creates a new compiler, which creates a new instance of the plugin, etc.
102
+ plugin.name !== 'vanilla-extract' &&
103
+ // Skip Remix because it throws an error if it's not loaded with a config file.
104
+ // If it _is_ loaded with a config file, it will create an infinite loop because it
105
+ // also has a child compiler which uses the same mechanism to load the config file.
106
+ // https://github.com/remix-run/remix/pull/7990#issuecomment-1809356626
107
+ plugin.name !== 'remix')
108
+ }
95
109
  });
96
110
  }
97
111
  },
98
112
  buildEnd() {
99
113
  var _compiler;
100
- (_compiler = compiler) === null || _compiler === void 0 ? void 0 : _compiler.close();
114
+ (_compiler = compiler) === null || _compiler === void 0 || _compiler.close();
101
115
  },
102
116
  async transform(code, id) {
103
117
  const [validId] = id.split('?');
@@ -18,10 +18,11 @@ function vanillaExtractPlugin({
18
18
  unstable_mode: mode = 'emitCss'
19
19
  } = {}) {
20
20
  let config;
21
- let userConfig;
21
+ let configEnv;
22
22
  let server;
23
23
  let packageName;
24
24
  let compiler;
25
+ const vitePromise = import('vite');
25
26
  const getIdentOption = () => identifiers ?? (config.mode === 'production' ? 'short' : 'debug');
26
27
  const getAbsoluteId = filePath => {
27
28
  let resolvedId = filePath;
@@ -66,38 +67,51 @@ function vanillaExtractPlugin({
66
67
  configureServer(_server) {
67
68
  server = _server;
68
69
  },
69
- config(viteUserConfig) {
70
- userConfig = viteUserConfig;
70
+ config(_userConfig, _configEnv) {
71
+ configEnv = _configEnv;
71
72
  return {
72
73
  ssr: {
73
74
  external: ['@vanilla-extract/css', '@vanilla-extract/css/fileScope', '@vanilla-extract/css/adapter']
74
75
  }
75
76
  };
76
77
  },
77
- async configResolved(resolvedConfig) {
78
- config = resolvedConfig;
78
+ async configResolved(_resolvedConfig) {
79
+ config = _resolvedConfig;
79
80
  packageName = integration.getPackageInfo(config.root).name;
81
+ },
82
+ async buildStart() {
80
83
  if (mode !== 'transform') {
81
- var _userConfig$plugins;
84
+ var _configFile$config$pl;
85
+ const {
86
+ loadConfigFromFile
87
+ } = await vitePromise;
88
+ const configFile = await loadConfigFromFile({
89
+ command: config.command,
90
+ mode: config.mode,
91
+ isSsrBuild: configEnv.isSsrBuild
92
+ }, config.configFile);
82
93
  compiler = integration.createCompiler({
83
94
  root: config.root,
84
95
  identifiers: getIdentOption(),
85
96
  cssImportSpecifier: fileIdToVirtualId,
86
- viteResolve: config.resolve,
87
- vitePlugins: (_userConfig$plugins = userConfig.plugins) === null || _userConfig$plugins === void 0 ? void 0 : _userConfig$plugins.flat().filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
88
- // Prevent an infinite loop where the compiler creates a new instance of the plugin,
89
- // which creates a new compiler, which creates a new instance of the plugin, etc.
90
- plugin.name !== 'vanilla-extract' &&
91
- // Skip Vitest plugins
92
- plugin.name !== 'vitest' && !plugin.name.startsWith('vitest:') &&
93
- // Skip Remix because it throws an error if it's not loaded with a config file
94
- plugin.name !== 'remix')
97
+ viteConfig: {
98
+ ...(configFile === null || configFile === void 0 ? void 0 : configFile.config),
99
+ plugins: configFile === null || configFile === void 0 || (_configFile$config$pl = configFile.config.plugins) === null || _configFile$config$pl === void 0 ? void 0 : _configFile$config$pl.flat().filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
100
+ // Prevent an infinite loop where the compiler creates a new instance of the plugin,
101
+ // which creates a new compiler, which creates a new instance of the plugin, etc.
102
+ plugin.name !== 'vanilla-extract' &&
103
+ // Skip Remix because it throws an error if it's not loaded with a config file.
104
+ // If it _is_ loaded with a config file, it will create an infinite loop because it
105
+ // also has a child compiler which uses the same mechanism to load the config file.
106
+ // https://github.com/remix-run/remix/pull/7990#issuecomment-1809356626
107
+ plugin.name !== 'remix')
108
+ }
95
109
  });
96
110
  }
97
111
  },
98
112
  buildEnd() {
99
113
  var _compiler;
100
- (_compiler = compiler) === null || _compiler === void 0 ? void 0 : _compiler.close();
114
+ (_compiler = compiler) === null || _compiler === void 0 || _compiler.close();
101
115
  },
102
116
  async transform(code, id) {
103
117
  const [validId] = id.split('?');
@@ -10,10 +10,11 @@ function vanillaExtractPlugin({
10
10
  unstable_mode: mode = 'emitCss'
11
11
  } = {}) {
12
12
  let config;
13
- let userConfig;
13
+ let configEnv;
14
14
  let server;
15
15
  let packageName;
16
16
  let compiler;
17
+ const vitePromise = import('vite');
17
18
  const getIdentOption = () => identifiers ?? (config.mode === 'production' ? 'short' : 'debug');
18
19
  const getAbsoluteId = filePath => {
19
20
  let resolvedId = filePath;
@@ -58,38 +59,51 @@ function vanillaExtractPlugin({
58
59
  configureServer(_server) {
59
60
  server = _server;
60
61
  },
61
- config(viteUserConfig) {
62
- userConfig = viteUserConfig;
62
+ config(_userConfig, _configEnv) {
63
+ configEnv = _configEnv;
63
64
  return {
64
65
  ssr: {
65
66
  external: ['@vanilla-extract/css', '@vanilla-extract/css/fileScope', '@vanilla-extract/css/adapter']
66
67
  }
67
68
  };
68
69
  },
69
- async configResolved(resolvedConfig) {
70
- config = resolvedConfig;
70
+ async configResolved(_resolvedConfig) {
71
+ config = _resolvedConfig;
71
72
  packageName = getPackageInfo(config.root).name;
73
+ },
74
+ async buildStart() {
72
75
  if (mode !== 'transform') {
73
- var _userConfig$plugins;
76
+ var _configFile$config$pl;
77
+ const {
78
+ loadConfigFromFile
79
+ } = await vitePromise;
80
+ const configFile = await loadConfigFromFile({
81
+ command: config.command,
82
+ mode: config.mode,
83
+ isSsrBuild: configEnv.isSsrBuild
84
+ }, config.configFile);
74
85
  compiler = createCompiler({
75
86
  root: config.root,
76
87
  identifiers: getIdentOption(),
77
88
  cssImportSpecifier: fileIdToVirtualId,
78
- viteResolve: config.resolve,
79
- vitePlugins: (_userConfig$plugins = userConfig.plugins) === null || _userConfig$plugins === void 0 ? void 0 : _userConfig$plugins.flat().filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
80
- // Prevent an infinite loop where the compiler creates a new instance of the plugin,
81
- // which creates a new compiler, which creates a new instance of the plugin, etc.
82
- plugin.name !== 'vanilla-extract' &&
83
- // Skip Vitest plugins
84
- plugin.name !== 'vitest' && !plugin.name.startsWith('vitest:') &&
85
- // Skip Remix because it throws an error if it's not loaded with a config file
86
- plugin.name !== 'remix')
89
+ viteConfig: {
90
+ ...(configFile === null || configFile === void 0 ? void 0 : configFile.config),
91
+ plugins: configFile === null || configFile === void 0 || (_configFile$config$pl = configFile.config.plugins) === null || _configFile$config$pl === void 0 ? void 0 : _configFile$config$pl.flat().filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin &&
92
+ // Prevent an infinite loop where the compiler creates a new instance of the plugin,
93
+ // which creates a new compiler, which creates a new instance of the plugin, etc.
94
+ plugin.name !== 'vanilla-extract' &&
95
+ // Skip Remix because it throws an error if it's not loaded with a config file.
96
+ // If it _is_ loaded with a config file, it will create an infinite loop because it
97
+ // also has a child compiler which uses the same mechanism to load the config file.
98
+ // https://github.com/remix-run/remix/pull/7990#issuecomment-1809356626
99
+ plugin.name !== 'remix')
100
+ }
87
101
  });
88
102
  }
89
103
  },
90
104
  buildEnd() {
91
105
  var _compiler;
92
- (_compiler = compiler) === null || _compiler === void 0 ? void 0 : _compiler.close();
106
+ (_compiler = compiler) === null || _compiler === void 0 || _compiler.close();
93
107
  },
94
108
  async transform(code, id) {
95
109
  const [validId] = id.split('?');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanilla-extract/vite-plugin",
3
- "version": "4.0.3",
3
+ "version": "4.0.5",
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",
@@ -15,10 +15,10 @@
15
15
  "author": "SEEK",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@vanilla-extract/integration": "^7.0.0"
18
+ "@vanilla-extract/integration": "^7.1.0"
19
19
  },
20
20
  "devDependencies": {
21
- "vite": "npm:vite@^5.0.11"
21
+ "vite": "^5.0.11"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "vite": "^4.0.3 || ^5.0.0"