Skip to content

Commit

Permalink
fix: insert relative imports for CSS files, #178
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Nov 26, 2017
1 parent 8c94761 commit 908dcd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ describe('preval-extract babel plugin with extraction enabled', () => {
{ filename: filename2 }
);

expect(transpiled1).toMatch(
`require('${path.join(process.cwd(), '.linaria-cache/test1.css')}')`
);
expect(transpiled2).toMatch(
`require('${path.join(process.cwd(), '.linaria-cache/test2.css')}')`
);
expect(transpiled1).toMatch(`require('./.linaria-cache/test1.css')`);
expect(transpiled2).toMatch(`require('./.linaria-cache/test2.css')`);

expect(data1).toMatchSnapshot();
expect(data2).toMatchSnapshot();
Expand Down
8 changes: 6 additions & 2 deletions src/babel/preval-extract/extractStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export default function extractStyles(
const filename = single
? path.join(process.cwd(), outDir, basename)
: getOutputFilename(relativeCurrentFilename, outDir);
const importPath = `./${path.relative(
path.dirname(absCurrentFilename),
filename
)}`;

if (!extract) {
return;
Expand All @@ -132,7 +136,7 @@ export default function extractStyles(
stylesCache[absCurrentFilename] = data;
} else {
if (hasCachedStyles(filename, data)) {
addRequireForCss(types, program, filename);
addRequireForCss(types, program, importPath);
return;
}
stylesCache[filename] = data;
Expand All @@ -146,7 +150,7 @@ export default function extractStyles(
);
} else {
outputStylesToFile(filename, withPreamble(data));
addRequireForCss(types, program, filename);
addRequireForCss(types, program, importPath);
}
}

Expand Down

0 comments on commit 908dcd7

Please sign in to comment.