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

fix: postcss.config.* file not working #6670

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/rich-cooks-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-js/uni-builder': patch
---

fix: postcss.config not works
17 changes: 13 additions & 4 deletions packages/cli/uni-builder/src/shared/plugins/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ export const pluginPostcss = ({
return mergeEnvironmentConfig(
{
tools: {
postcss: {
postcssOptions: {
plugins,
},
postcss: opts => {
if (typeof opts.postcssOptions === 'object') {
opts.postcssOptions.plugins!.push(...plugins);
return;
9aoy marked this conversation as resolved.
Show resolved Hide resolved
} else if (typeof opts.postcssOptions === 'function') {
chenjiahan marked this conversation as resolved.
Show resolved Hide resolved
const originFn = opts.postcssOptions;
opts.postcssOptions = loaderContext => {
const options = originFn(loaderContext);
options.plugins!.push(...plugins);
return options;
};
return;
}
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,55 +143,6 @@ exports[`plugin-postcssLegacy > should allow tools.postcss to override the plugi
"postcssOptions": {
"config": false,
"plugins": [
{
"Once": [Function],
9aoy marked this conversation as resolved.
Show resolved Hide resolved
"postcssPlugin": "postcss-flexbugs-fixes",
},
{
"postcssPlugin": "postcss-custom-properties",
"prepare": [Function],
},
{
"Declaration": [Function],
"postcssPlugin": "postcss-initial",
},
{
"Declaration": [Function],
"postcssPlugin": "postcss-page-break",
},
{
"Once": [Function],
"postcssPlugin": "postcss-font-variant",
},
{
"AtRule": {
"custom-media": [Function],
"media": [Function],
},
"postcssPlugin": "postcss-media-minmax",
},
{
"Rule": [Function],
"postcssPlugin": "postcss-nesting",
},
{
"browsers": [
"> 0.01%",
"not dead",
"not op_mini all",
],
"info": [Function],
"options": {
"flexbox": "no-2009",
"overrideBrowserslist": [
"> 0.01%",
"not dead",
"not op_mini all",
],
},
"postcssPlugin": "autoprefixer",
"prepare": [Function],
},
{
"AtRule": {},
"postcssPlugin": "postcss-plugin-test",
Expand Down Expand Up @@ -242,55 +193,6 @@ exports[`plugin-postcssLegacy > should allow tools.postcss to override the plugi
"postcssOptions": {
"config": false,
"plugins": [
{
"Once": [Function],
"postcssPlugin": "postcss-flexbugs-fixes",
},
{
"postcssPlugin": "postcss-custom-properties",
"prepare": [Function],
},
{
"Declaration": [Function],
"postcssPlugin": "postcss-initial",
},
{
"Declaration": [Function],
"postcssPlugin": "postcss-page-break",
},
{
"Once": [Function],
"postcssPlugin": "postcss-font-variant",
},
{
"AtRule": {
"custom-media": [Function],
"media": [Function],
},
"postcssPlugin": "postcss-media-minmax",
},
{
"Rule": [Function],
"postcssPlugin": "postcss-nesting",
},
{
"browsers": [
"> 0.01%",
"not dead",
"not op_mini all",
],
"info": [Function],
"options": {
"flexbox": "no-2009",
"overrideBrowserslist": [
"> 0.01%",
"not dead",
"not op_mini all",
],
},
"postcssPlugin": "autoprefixer",
"prepare": [Function],
},
{
"AtRule": {},
"postcssPlugin": "postcss-plugin-test",
Expand Down Expand Up @@ -359,55 +261,6 @@ exports[`plugin-postcssLegacy > should allow tools.postcss to override the plugi
"postcssOptions": {
"config": false,
"plugins": [
{
"Once": [Function],
"postcssPlugin": "postcss-flexbugs-fixes",
},
{
"postcssPlugin": "postcss-custom-properties",
"prepare": [Function],
},
{
"Declaration": [Function],
"postcssPlugin": "postcss-initial",
},
{
"Declaration": [Function],
"postcssPlugin": "postcss-page-break",
},
{
"Once": [Function],
"postcssPlugin": "postcss-font-variant",
},
{
"AtRule": {
"custom-media": [Function],
"media": [Function],
},
"postcssPlugin": "postcss-media-minmax",
},
{
"Rule": [Function],
"postcssPlugin": "postcss-nesting",
},
{
"browsers": [
"> 0.01%",
"not dead",
"not op_mini all",
],
"info": [Function],
"options": {
"flexbox": "no-2009",
"overrideBrowserslist": [
"> 0.01%",
"not dead",
"not op_mini all",
],
},
"postcssPlugin": "autoprefixer",
"prepare": [Function],
},
{
"AtRule": {},
"postcssPlugin": "postcss-plugin-test",
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a postcss folder and add more test cases for different usages?

  • Merge PostCSS plugins
  • Read postcss.config.*
  • Usage with @modern-js/plugin-tailwindcss

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { applyBaseConfig } from '../../../../utils/applyBaseConfig';

export default applyBaseConfig({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "integration-tailwindcss-without-plugin",
"version": "2.9.0",
"dependencies": {
"@modern-js/app-tools": "workspace:*",
"@modern-js/runtime": "workspace:*",
"postcss": "^8.4.35",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwindcss": "^3.3.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: {
tailwindcss: {},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'tailwindcss/base.css';
import 'tailwindcss/components.css';
import 'tailwindcss/utilities.css';

const App = () => (
<div className="h-12 w-48">
<p className="text-xl font-medium text-red-500">hello world</p>
</div>
);

export default App;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
theme: {
colors: {
'red-500': '#1fb6ff',
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import { fixtures, launchAppWithPage } from './utils';

describe('use tailwindcss without modern plugin', () => {
test(`should load tailwind & tailwind.config.js correctly`, async () => {
const appDir = path.resolve(fixtures, 'tailwindcss-without-plugin');
const { page, clear } = await launchAppWithPage(appDir);

const textColor = await page.$eval('p', p =>
window.getComputedStyle(p).getPropertyValue('color'),
);

expect(textColor).toBe('rgb(31, 182, 255)');

await clear();
});
});
Loading