Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline import #248

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('@jest/types').Config.InitialOptions} */

module.exports = {
roots: ['<rootDir>/demo'],
roots: ['<rootDir>/demo', '<rootDir>/src'],
collectCoverageFrom: [
'demo/**/*.{js,jsx,ts,tsx}',
'!demo/**/*.d.ts',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"connect": "^3.7.0",
"find-node-modules": "^2.1.3",
"open": "^8.4.0",
"postcss-import": "^14.1.0",
"postcss-load-config": "^4.0.1",
"sirv": "^2.0.2",
"slash": "^3.0.0",
Expand Down
12 changes: 2 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/__tests__/230/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@tailwind base;

@layer base {
#id {
@apply flex min-h-screen flex-col;
}
}
10 changes: 10 additions & 0 deletions src/__tests__/230/components.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@tailwind components;

@layer components {
.card {
background-color: theme('colors.white');
border-radius: theme('borderRadius.lg');
padding: theme('spacing.6');
box-shadow: theme('boxShadow.xl');
}
}
3 changes: 3 additions & 0 deletions src/__tests__/230/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import 'base.css';
@import 'components.css';
@import 'utils.css';
12 changes: 12 additions & 0 deletions src/__tests__/230/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<p class="card lg:dark:content-auto"></p>
</body>
</html>
15 changes: 15 additions & 0 deletions src/__tests__/230/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://github.com/nvh95/jest-preview/issues/230
import cssTransform from '../../preconfigTransform/css';
import fs from 'fs';
import path from 'path';

const filename = path.join(__dirname, 'index.css');
const cssSrc = fs.readFileSync(filename, 'utf8');

describe(`Tailwind CSS doesn't get compiled in @import'ed files`, () => {
it('should inline @import', () => {
expect(cssTransform.process(cssSrc, filename).code).toContain(
'https://tailwindcss.com',
);
});
});
24 changes: 24 additions & 0 deletions src/__tests__/230/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
'postcss-trolling': {
comicSans: true,
aling: false,
blur: false,
blurBlink: false,
clearfix: false,
heigth: false,
hideCursor: false,
hideOdd: false,
ms: false,
ren: false,
rotate: false,
roulette: false,
slowlyGrowText: false,
verImportant: false,
wait: false,
zIndex: false,
},
},
};
7 changes: 7 additions & 0 deletions src/__tests__/230/tailwind.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
content: ['./index.html'],
theme: {
extend: {},
},
plugins: [],
};
7 changes: 7 additions & 0 deletions src/__tests__/230/utils.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@tailwind utilities;

@layer utilities {
.content-auto {
content-visibility: auto;
}
}
3 changes: 2 additions & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function processPostCss(
// TODO: We have to re-execute "postcssrc()" every CSS file.
// Can we do better? Singleton?
postcssrc().then(({ plugins, options }) => {
// TODO: If "isModule" is true, append config for "postcss-modules"
plugins.unshift(require('postcss-import')())
if (isModule) {
plugins.push(
${cssModulesPluginsContent},
Expand All @@ -319,6 +319,7 @@ const cssSrc = ${JSON.stringify(src)};

let plugins = [];
if (isModule) {
plugins.unshift(require('postcss-import')())
plugins.push(
${cssModulesPluginsContent},
)
Expand Down