Skip to content

Commit ef92d3e

Browse files
authored
Merge pull request #6 from steveblue/bugfix/custom-regex
fix: custom regex
2 parents a0d6793 + 7f546b3 commit ef92d3e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

dist/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function inlinePostCSS(options = {}) {
1010
const styleRegex = options.styleRegex
1111
? options.styleRegex
1212
: /(css\`((.|\n)*)\`)/g;
13+
const hasCustomRegex = options.styleRegex ? true : false;
1314
return {
1415
name: 'inline-postcss',
1516
transform(code, id) {
@@ -36,7 +37,10 @@ function inlinePostCSS(options = {}) {
3637
: require(path.join(configFolder, 'postcss.config.js'))({
3738
env: process.env.NODE_ENV,
3839
});
39-
const css = code.match(styleRegex)[0].split('`')[1];
40+
let css = code.match(styleRegex)[0];
41+
if (options.escapeTemplateString || !hasCustomRegex) {
42+
css = css.split('`')[1];
43+
}
4044
const opts = {
4145
from: options.from ? path.join(process.cwd(), options.from) : id,
4246
to: options.to ? path.join(process.cwd(), options.to) : id,

index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function inlinePostCSS(options: any = {}) {
1010
const styleRegex = options.styleRegex
1111
? options.styleRegex
1212
: /(css\`((.|\n)*)\`)/g;
13+
const hasCustomRegex = options.styleRegex ? true : false;
1314
return {
1415
name: 'inline-postcss',
1516
transform(code, id) {
@@ -37,7 +38,10 @@ export default function inlinePostCSS(options: any = {}) {
3738
: require(path.join(configFolder, 'postcss.config.js'))({
3839
env: process.env.NODE_ENV,
3940
});
40-
const css = code.match(styleRegex)[0].split('`')[1];
41+
let css = code.match(styleRegex)[0];
42+
if (options.escapeTemplateString || !hasCustomRegex) {
43+
css = css.split('`')[1];
44+
}
4145
const opts = {
4246
from: options.from ? path.join(process.cwd(), options.from) : id,
4347
to: options.to ? path.join(process.cwd(), options.to) : id,

test/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function write({ input, outDir, options }) {
1616
plugins: [
1717
inlinePostCSS({
1818
styleRegex: /css\`((.|\n)*)\`(;)/gm,
19+
escapeTemplateString: true,
1920
plugins: [require('postcss-rgb-plz')],
2021
}),
2122
],

0 commit comments

Comments
 (0)