Skip to content

Commit 711ed0c

Browse files
committed
chore: add customLoader
1 parent eb0f574 commit 711ed0c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

packages/unplugin-tailwindcss-mangle/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@types/micromatch": "^4.0.2",
9090
"@types/semver": "^7.3.13",
9191
"pkg-types": "^1.0.2",
92+
"simple-functional-loader": "^1.2.1",
9293
"tailwindcss": "^3.3.2",
9394
"tslib": "^2.5.0",
9495
"vite": "^4.3.3",

packages/unplugin-tailwindcss-mangle/src/index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { sources } from 'webpack'
1010
import path from 'path'
1111
import fs from 'fs'
1212
import { getOptions } from './options'
13+
const { createLoader } = require('simple-functional-loader')
1314

1415
// cache map
1516
const outputCachedMap = new Map<
@@ -77,7 +78,7 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
7778
}
7879
},
7980
webpack(compiler) {
80-
const Compilation = compiler.webpack.Compilation
81+
const { NormalModule, Compilation } = compiler.webpack
8182
const { ConcatSource } = compiler.webpack.sources
8283
function getAssetPath(outputPath: string, file: string, abs: boolean = true) {
8384
const fn = abs ? path.resolve : path.relative
@@ -95,7 +96,30 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
9596
console.log(error)
9697
}
9798
}
99+
const customLoader = {
100+
...createLoader(function (source: string) {
101+
return source
102+
}),
103+
ident: null,
104+
type: null
105+
}
98106
compiler.hooks.compilation.tap(pluginName, (compilation) => {
107+
NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (loaderContext, module) => {
108+
const idx = module.loaders.findIndex((x) => x.loader.includes('css-loader'))
109+
// vue-loader/dist/stylePostLoader.
110+
// vue-style-loader
111+
if (idx > -1) {
112+
module.loaders.splice(idx, 0, customLoader)
113+
// console.log(module.resource, module.loaders.map(x => x.loader))
114+
// if(/css/.test(module.resource)){
115+
// const idx = module.loaders.findIndex((x) => x.loader === 'style-loader')
116+
// console.log(idx)
117+
// }
118+
}
119+
120+
121+
122+
})
99123
compilation.hooks.processAssets.tap(
100124
{
101125
name: pluginName,

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)