Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mellyeliu committed Dec 3, 2024
2 parents a90bc8e + 1b019be commit 676cd2d
Show file tree
Hide file tree
Showing 20 changed files with 812 additions and 640 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

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

/**
* The @stylex directive is used by the @stylexjs/postcss-plugin.
* It is automatically replaced with generated CSS during builds.
*/
@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 676cd2d

Please sign in to comment.