UNPKG

vite-plugin-vue-css-modules

Version:

✨ Ultimate solution for using CSS modules without any hassle. Automatic replacement for Vue templates and scripts

14 lines (13 loc) 674 B
import { hyphenate } from "@vue/shared"; export const transformScript = (source, contentOffset, sfcTransform, localNameGenerator) => { const rgx = /\$cssModule(?:\[['"`]([\w\-]+)['"`]\]|\.(\w+))/g; let matchResult = rgx.exec(source); while (matchResult) { const [match, classNameComputed, classNameProp] = matchResult; const sfcOffsetStart = contentOffset + matchResult.index; let name = classNameProp ? hyphenate(classNameProp) : classNameComputed; name = JSON.stringify(localNameGenerator(name)); sfcTransform.update(sfcOffsetStart, sfcOffsetStart + match.length, name); matchResult = rgx.exec(source); } };