Skip to content

Commit

Permalink
feat: add postcss-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
javascripter committed Nov 24, 2024
1 parent d980195 commit fea3d0e
Show file tree
Hide file tree
Showing 12 changed files with 828 additions and 507 deletions.
1 change: 1 addition & 0 deletions apps/nextjs-example/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
// https://stylexjs.com/docs/api/configuration/babel-plugin/
{
dev: process.env.NODE_ENV === 'development',
runtimeInjection: false,
genConditionalClasses: true,
treeshakeCompensation: true,
aliases: {
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs-example/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import './globals.css';
import './stylex.css';
import { globalTokens as $ } from '@/app/globalTokens.stylex';
import * as stylex from '@stylexjs/stylex';

Expand Down
14 changes: 14 additions & 0 deletions apps/nextjs-example/app/stylex.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

/**
* The @stylex directive is used by the @stylexjs/postcss-plugin.
* It is automatically replaced with generated CSS during builds.
*/
@stylex;
14 changes: 2 additions & 12 deletions apps/nextjs-example/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@
*/

/** @type {import('next').NextConfig} */
const path = require('path');
const stylexPlugin = require('@stylexjs/nextjs-plugin');
const babelrc = require('./.babelrc.js');
const plugins = babelrc.plugins;
const [_name, options] = plugins.find(
(plugin) => Array.isArray(plugin) && plugin[0] === '@stylexjs/babel-plugin',
);
const rootDir = options.unstable_moduleResolution.rootDir ?? __dirname;
const aliases = options.aliases ?? undefined;
const useCSSLayers = options.useCSSLayers ?? undefined;

module.exports = stylexPlugin({ rootDir, aliases, useCSSLayers })({
module.exports = {
transpilePackages: ['@stylexjs/open-props'],
});
};
5 changes: 1 addition & 4 deletions apps/nextjs-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"private": true,
"scripts": {
"clean": "rimraf .next",
"predev": "npm run clean",
"prebuild": "npm run clean",
"dev": "next dev",
"build": "next build",
"start": "next start",
Expand All @@ -20,9 +18,8 @@
"next": "14.0.1"
},
"devDependencies": {
"@stylexjs/babel-plugin": "^0.7.5",
"@stylexjs/eslint-plugin": "^0.7.5",
"@stylexjs/nextjs-plugin": "^0.7.5",
"@stylexjs/postcss-plugin": "^0.9.3",
"@types/node": "^22.7.6",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
Expand Down
22 changes: 22 additions & 0 deletions apps/nextjs-example/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

module.exports = {
plugins: {
'@stylexjs/postcss-plugin': {
include: [
'app/**/*.{js,jsx,ts,tsx}',
'components/**/*.{js,jsx,ts,tsx}',
'./node_modules/@stylexjs/open-props/lib/**/*.js',
],
useCSSLayers: true,
},
autoprefixer: {},
},
};
Loading

0 comments on commit fea3d0e

Please sign in to comment.