Skip to content

Commit

Permalink
feat: allow to disable pipeline extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 4, 2023
1 parent 29e5859 commit d3b4120
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/types.ts
Expand Up @@ -664,8 +664,10 @@ export interface ContentOptions {
* Filters to determine whether to extract certain modules from the build tools' transformation pipeline.
*
* Currently only works for Vite and Webpack integration.
*
* Set `false` to disable.
*/
pipeline?: {
pipeline?: false | {
/**
* Patterns that filter the files being extracted.
* Supports regular expressions and `picomatch` glob patterns.
Expand Down
12 changes: 7 additions & 5 deletions packages/nuxt/src/options.ts
Expand Up @@ -27,10 +27,12 @@ export function resolveOptions(options: UnocssNuxtOptions) {
}
}

options.content ||= {}
options.content.pipeline ||= {}
options.content.pipeline.exclude ||= defaultPipelineExclude
if (Array.isArray(options.content.pipeline.exclude))
options.content ??= {}
options.content.pipeline ??= {}
if (options.content.pipeline !== false) {
options.content.pipeline.exclude ??= defaultPipelineExclude
if (Array.isArray(options.content.pipeline.exclude))
// ignore macro files created by Nuxt
options.content.pipeline.exclude.push(/\?macro=true/)
options.content.pipeline.exclude.push(/\?macro=true/)
}
}
10 changes: 6 additions & 4 deletions packages/shared-integration/src/context.ts
Expand Up @@ -38,10 +38,12 @@ export function createContext<Config extends UserConfig<any> = UserConfig<any>>(
configFileList = result.sources
uno.setConfig(rawConfig)
uno.config.envMode = 'dev'
rollupFilter = createFilter(
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
)
rollupFilter = rawConfig.content?.pipeline === false
? () => false
: createFilter(
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
)
tokens.clear()
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)))
invalidate()
Expand Down
10 changes: 6 additions & 4 deletions packages/vite/src/modes/vue-scoped.ts
Expand Up @@ -18,10 +18,12 @@ export function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin {
enforce: 'pre',
async configResolved() {
const { config } = await ready
filter = createFilter(
config.content?.pipeline?.include ?? config.include ?? [/\.vue$/],
config.content?.pipeline?.exclude ?? config.exclude ?? defaultPipelineExclude,
)
filter = config.content?.pipeline === false
? () => false
: createFilter(
config.content?.pipeline?.include ?? config.include ?? [/\.vue$/],
config.content?.pipeline?.exclude ?? config.exclude ?? defaultPipelineExclude,
)
},
transform(code, id) {
if (!filter(id))
Expand Down

0 comments on commit d3b4120

Please sign in to comment.