Skip to content

Commit

Permalink
Merge branch 'facebook:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
p0nch000 authored Nov 27, 2024
2 parents 554931b + 307a6d5 commit 93b3500
Show file tree
Hide file tree
Showing 26 changed files with 737 additions and 502 deletions.
2 changes: 1 addition & 1 deletion apps/cli-example/.stylex.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
cssBundleName: 'stylex_bundle.css',
babelPresets: [
['@babel/preset-typescript', { allExtensions: true, isTSX: true }],
'@babel/preset-react',
// '@babel/preset-react',
],
modules_EXPERIMENTAL: [
['@stylexjs/open-props', { ignore: ['src', '__tests__'] }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

@layer reset {
@layer resets {
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
}

@stylex;
2 changes: 1 addition & 1 deletion apps/nextjs-example/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* 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.
*
*
*/
const path = require('path');
module.exports = {
presets: ['next/babel'],
Expand All @@ -8,6 +16,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
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'],
});
};
7 changes: 2 additions & 5 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 @@ -14,18 +12,17 @@
"dependencies": {
"@stylexjs/stylex": "^0.7.5",
"@stylexjs/open-props": "^0.7.5",
"bright": "^0.8.5",
"react": "^18",
"react-dom": "^18",
"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",
"@types/json-schema": "^7.0.15",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.1",
"eslint-config-next": "14.0.1",
Expand Down
57 changes: 57 additions & 0 deletions apps/nextjs-example/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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.
*
*
*/

const fs = require('fs');
const path = require('path');

const projectRoot = __dirname;
const monorepoRoot = path.join(projectRoot, '../../');

function getPackageIncludePaths(packageName, nodeModulePaths) {
let packagePath = null;

for (const nodeModulePath of nodeModulePaths) {
const packageJsonPath = path.resolve(
nodeModulePath,
packageName,
'package.json',
);
if (fs.existsSync(packageJsonPath)) {
packagePath = path.dirname(packageJsonPath);
break;
}
}
if (!packagePath) {
throw new Error(`Could not find package ${packageName}`);
}

return [
path.join(packagePath, '**/*.{js,mjs}'),
'!' + path.join(packagePath, 'node_modules/**/*.{js,mjs}'),
];
}

const openPropsIncludePaths = getPackageIncludePaths('@stylexjs/open-props', [
path.join(projectRoot, 'node_modules'),
path.join(monorepoRoot, 'node_modules'),
]);

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

0 comments on commit 93b3500

Please sign in to comment.