Skip to content

Commit

Permalink
Merge pull request #6 from steveblue/bugfix/custom-regex
Browse files Browse the repository at this point in the history
fix: custom regex
  • Loading branch information
steveblue authored Jan 20, 2021
2 parents a0d6793 + 7f546b3 commit ef92d3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function inlinePostCSS(options = {}) {
const styleRegex = options.styleRegex
? options.styleRegex
: /(css\`((.|\n)*)\`)/g;
const hasCustomRegex = options.styleRegex ? true : false;
return {
name: 'inline-postcss',
transform(code, id) {
Expand All @@ -36,7 +37,10 @@ function inlinePostCSS(options = {}) {
: require(path.join(configFolder, 'postcss.config.js'))({
env: process.env.NODE_ENV,
});
const css = code.match(styleRegex)[0].split('`')[1];
let css = code.match(styleRegex)[0];
if (options.escapeTemplateString || !hasCustomRegex) {
css = css.split('`')[1];
}
const opts = {
from: options.from ? path.join(process.cwd(), options.from) : id,
to: options.to ? path.join(process.cwd(), options.to) : id,
Expand Down
6 changes: 5 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function inlinePostCSS(options: any = {}) {
const styleRegex = options.styleRegex
? options.styleRegex
: /(css\`((.|\n)*)\`)/g;
const hasCustomRegex = options.styleRegex ? true : false;
return {
name: 'inline-postcss',
transform(code, id) {
Expand Down Expand Up @@ -37,7 +38,10 @@ export default function inlinePostCSS(options: any = {}) {
: require(path.join(configFolder, 'postcss.config.js'))({
env: process.env.NODE_ENV,
});
const css = code.match(styleRegex)[0].split('`')[1];
let css = code.match(styleRegex)[0];
if (options.escapeTemplateString || !hasCustomRegex) {
css = css.split('`')[1];
}
const opts = {
from: options.from ? path.join(process.cwd(), options.from) : id,
to: options.to ? path.join(process.cwd(), options.to) : id,
Expand Down
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function write({ input, outDir, options }) {
plugins: [
inlinePostCSS({
styleRegex: /css\`((.|\n)*)\`(;)/gm,
escapeTemplateString: true,
plugins: [require('postcss-rgb-plz')],
}),
],
Expand Down

0 comments on commit ef92d3e

Please sign in to comment.