(config: ResolvedConfig)
| 167 | } |
| 168 | |
| 169 | export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin { |
| 170 | const resolve = createBackCompatIdResolver(config, { |
| 171 | preferRelative: true, |
| 172 | tryIndex: false, |
| 173 | extensions: [], |
| 174 | }) |
| 175 | |
| 176 | const getFilter = perEnvironmentState((environment: Environment) => { |
| 177 | const { include, exclude } = |
| 178 | environment.config.build.dynamicImportVarsOptions |
| 179 | return createFilter(include, exclude) |
| 180 | }) |
| 181 | |
| 182 | return { |
| 183 | name: 'vite:dynamic-import-vars', |
| 184 | |
| 185 | applyToEnvironment(environment) { |
| 186 | if (environment.config.isBundled) { |
| 187 | const { include, exclude } = |
| 188 | environment.config.build.dynamicImportVarsOptions |
| 189 | |
| 190 | return nativeDynamicImportVarsPlugin({ |
| 191 | include, |
| 192 | exclude, |
| 193 | resolver(id, importer) { |
| 194 | return resolve(environment, id, importer) |
| 195 | }, |
| 196 | sourcemap: !!environment.config.build.sourcemap, |
| 197 | }) |
| 198 | } |
| 199 | return true |
| 200 | }, |
| 201 | |
| 202 | resolveId: { |
| 203 | filter: { id: exactRegex(dynamicImportHelperId) }, |
| 204 | handler(id) { |
| 205 | return id |
| 206 | }, |
| 207 | }, |
| 208 | |
| 209 | load: { |
| 210 | filter: { id: exactRegex(dynamicImportHelperId) }, |
| 211 | handler(_id) { |
| 212 | return `export default ${dynamicImportHelper.toString()}` |
| 213 | }, |
| 214 | }, |
| 215 | |
| 216 | transform: { |
| 217 | filter: { |
| 218 | id: { exclude: exactRegex(CLIENT_ENTRY) }, |
| 219 | code: hasDynamicImportRE, |
| 220 | }, |
| 221 | async handler(source, importer) { |
| 222 | const { environment } = this |
| 223 | if (!getFilter(this)(importer)) { |
| 224 | return |
| 225 | } |
| 226 |
no test coverage detected