( this: LoaderContext<LoaderOptions>, source: string, )
| 59 | } |
| 60 | |
| 61 | export default async function tailwindLoader( |
| 62 | this: LoaderContext<LoaderOptions>, |
| 63 | source: string, |
| 64 | ): Promise<void> { |
| 65 | let callback = this.async() |
| 66 | let options = this.getOptions() ?? {} |
| 67 | let inputFile = this.resourcePath |
| 68 | let resourceId = this.resource |
| 69 | let base = options.base ?? process.cwd() |
| 70 | let shouldOptimize = options.optimize ?? process.env.NODE_ENV === 'production' |
| 71 | let isCSSModuleFile = inputFile.endsWith('.module.css') |
| 72 | |
| 73 | using I = new Instrumentation() |
| 74 | |
| 75 | DEBUG && I.start(`[@tailwindcss/webpack] ${path.relative(base, inputFile)}`) |
| 76 | |
| 77 | // Bail out early if this is guaranteed to be a non-Tailwind CSS file. |
| 78 | { |
| 79 | DEBUG && I.start('Quick bail check') |
| 80 | let canBail = !/@(import|reference|theme|variant|config|plugin|apply|tailwind)\b/.test(source) |
| 81 | if (canBail) { |
| 82 | DEBUG && I.end('Quick bail check') |
| 83 | DEBUG && I.end(`[@tailwindcss/webpack] ${path.relative(base, inputFile)}`) |
| 84 | callback(null, source) |
| 85 | return |
| 86 | } |
| 87 | DEBUG && I.end('Quick bail check') |
| 88 | } |
| 89 | |
| 90 | try { |
| 91 | let context = getContextFromCache(resourceId, options) |
| 92 | let inputBasePath = path.dirname(path.resolve(inputFile)) |
| 93 | |
| 94 | // Whether this is the first build or not |
| 95 | let isInitialBuild = context.compiler === null |
| 96 | |
| 97 | async function createCompiler() { |
| 98 | DEBUG && I.start('Setup compiler') |
| 99 | if (context.fullRebuildPaths.length > 0 && !isInitialBuild) { |
| 100 | clearRequireCache(context.fullRebuildPaths) |
| 101 | } |
| 102 | |
| 103 | context.fullRebuildPaths = [] |
| 104 | |
| 105 | DEBUG && I.start('Create compiler') |
| 106 | let compiler = await compile(source, { |
| 107 | from: inputFile, |
| 108 | base: inputBasePath, |
| 109 | shouldRewriteUrls: true, |
| 110 | onDependency: (depPath) => context.fullRebuildPaths.push(depPath), |
| 111 | // In CSS Module files, we have to disable the `@property` polyfill since these will |
| 112 | // emit global `*` rules which are considered to be non-pure and will cause builds |
| 113 | // to fail. |
| 114 | polyfills: isCSSModuleFile ? Polyfills.All ^ Polyfills.AtProperty : Polyfills.All, |
| 115 | }) |
| 116 | DEBUG && I.end('Create compiler') |
| 117 | |
| 118 | DEBUG && I.end('Setup compiler') |
nothing calls this directly
no test coverage detected