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

Add emotion support to cra #8455

Closed
wants to merge 10 commits into from
4 changes: 4 additions & 0 deletions packages/babel-preset-react-app/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ module.exports = function(api, opts, env) {
isTypeScriptEnabled && [require('@babel/preset-typescript').default],
].filter(Boolean),
plugins: [
isEnvDevelopment
? [require('babel-plugin-emotion').default, { sourceMap: true }]
: require('babel-plugin-emotion').default,

// Strip flow types before any other transform, emulating the behavior
// order as-if the browser supported all of the succeeding features
// https://github.com/facebook/create-react-app/pull/5182
Expand Down
11 changes: 6 additions & 5 deletions packages/babel-preset-react-app/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "babel-preset-react-app",
"version": "9.1.0",
"description": "Babel preset used by Create React App",
"name": "xometry-babel-preset-react-app",
"version": "9.2.0",
"description": "Xometry Babel preset used by Xometry Create React App",
"repository": {
"type": "git",
"url": "https://github.com/facebook/create-react-app.git",
"url": "https://github.com/xometry/create-react-app.git",
"directory": "packages/babel-preset-react-app"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/facebook/create-react-app/issues"
"url": "https://github.com/xometry/create-react-app/issues"
},
"files": [
"create.js",
Expand Down Expand Up @@ -38,6 +38,7 @@
"@babel/preset-typescript": "7.7.4",
"@babel/runtime": "7.7.6",
"babel-plugin-dynamic-import-node": "2.3.0",
"babel-plugin-emotion": "^10.0.27",
"babel-plugin-macros": "2.8.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.24"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const scriptIndex = args.findIndex(
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];

if (['build', 'eject', 'start', 'test'].includes(script)) {
if (['build', 'eject', 'start', 'test', 'build-component'].includes(script)) {
const result = spawn.sync(
'node',
nodeArgs
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/config/jest/babelTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const babelJest = require('babel-jest');

module.exports = babelJest.createTransformer({
presets: [require.resolve('babel-preset-react-app')],
presets: [require.resolve('xometry-babel-preset-react-app')],
babelrc: false,
configFile: false,
});
36 changes: 20 additions & 16 deletions packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
// @remove-on-eject-end
const postcssNormalize = require('postcss-normalize');

const BUILD_ID = process.env.REACT_APP_BUILD_ID || '';

const appPackageJson = require(paths.appPackageJson);

// Source maps are resource heavy and can cause out of memory issue for large source files.
Expand Down Expand Up @@ -184,14 +186,14 @@ module.exports = function(webpackEnv) {
// There will be one main bundle, and one file per asynchronous chunk.
// In development, it does not produce real files.
filename: isEnvProduction
? 'static/js/[name].[contenthash:8].js'
: isEnvDevelopment && 'static/js/bundle.js',
? `static-${BUILD_ID}/js/[name].[contenthash:8].js`
: isEnvDevelopment && `static-${BUILD_ID}/js/bundle.js`,
// TODO: remove this when upgrading to webpack 5
futureEmitAssets: true,
// There are also additional JS chunk files if you use code splitting.
chunkFilename: isEnvProduction
? 'static/js/[name].[contenthash:8].chunk.js'
: isEnvDevelopment && 'static/js/[name].chunk.js',
? `static-${BUILD_ID}/js/[name].[contenthash:8].chunk.js`
: isEnvDevelopment && `static-${BUILD_ID}/js/[name].chunk.js`,
// We inferred the "public path" (such as / or /my-project) from homepage.
// We use "/" in development.
publicPath: publicPath,
Expand Down Expand Up @@ -270,8 +272,8 @@ module.exports = function(webpackEnv) {
: false,
},
cssProcessorPluginOptions: {
preset: ['default', { minifyFontValues: { removeQuotes: false } }]
}
preset: ['default', { minifyFontValues: { removeQuotes: false } }],
},
}),
],
// Automatically split vendor and commons
Expand Down Expand Up @@ -396,7 +398,7 @@ module.exports = function(webpackEnv) {
loader: require.resolve('url-loader'),
options: {
limit: imageInlineSizeLimit,
name: 'static/media/[name].[hash:8].[ext]',
name: `static-${BUILD_ID}/media/[name].[hash:8].[ext]`,
},
},
// Process application JS with Babel.
Expand All @@ -407,24 +409,24 @@ module.exports = function(webpackEnv) {
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
'babel-preset-react-app/webpack-overrides'
'xometry-babel-preset-react-app/webpack-overrides'
),
// @remove-on-eject-begin
babelrc: false,
configFile: false,
presets: [require.resolve('babel-preset-react-app')],
presets: [require.resolve('xometry-babel-preset-react-app')],
// Make sure we have a unique cache identifier, erring on the
// side of caution.
// We remove this when the user ejects because the default
// is sane and uses Babel options. Instead of options, we use
// the react-scripts and babel-preset-react-app versions.
// the react-scripts and xometry-babel-preset-react-app versions.
cacheIdentifier: getCacheIdentifier(
isEnvProduction
? 'production'
: isEnvDevelopment && 'development',
[
'babel-plugin-named-asset-import',
'babel-preset-react-app',
'xometry-babel-preset-react-app',
'react-dev-utils',
'react-scripts',
]
Expand Down Expand Up @@ -464,7 +466,9 @@ module.exports = function(webpackEnv) {
compact: false,
presets: [
[
require.resolve('babel-preset-react-app/dependencies'),
require.resolve(
'xometry-babel-preset-react-app/dependencies'
),
{ helpers: true },
],
],
Expand All @@ -478,7 +482,7 @@ module.exports = function(webpackEnv) {
: isEnvDevelopment && 'development',
[
'babel-plugin-named-asset-import',
'babel-preset-react-app',
'xometry-babel-preset-react-app',
'react-dev-utils',
'react-scripts',
]
Expand Down Expand Up @@ -570,7 +574,7 @@ module.exports = function(webpackEnv) {
// by webpacks internal loaders.
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
options: {
name: 'static/media/[name].[hash:8].[ext]',
name: `static-${BUILD_ID}/media/[name].[hash:8].[ext]`,
},
},
// ** STOP ** Are you adding a new loader?
Expand Down Expand Up @@ -644,8 +648,8 @@ module.exports = function(webpackEnv) {
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
filename: `static-${BUILD_ID}/css/[name].[contenthash:8].css`,
chunkFilename: `static-${BUILD_ID}/css/[name].[contenthash:8].chunk.css`,
}),
// Generate an asset manifest file with the following content:
// - "files" key: Mapping of all asset filenames to their corresponding
Expand Down
14 changes: 7 additions & 7 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "react-scripts",
"version": "3.3.0",
"description": "Configuration and scripts for Create React App.",
"name": "xometry-react-scripts",
"version": "3.5.0",
"description": "Xometry configuration and scripts for Create React App.",
"repository": {
"type": "git",
"url": "https://github.com/facebook/create-react-app.git",
"url": "https://github.com/xometry/create-react-app.git",
"directory": "packages/react-scripts"
},
"license": "MIT",
"engines": {
"node": ">=8.10"
},
"bugs": {
"url": "https://github.com/facebook/create-react-app/issues"
"url": "https://github.com/xometry/create-react-app/issues"
},
"files": [
"bin",
Expand All @@ -36,7 +36,6 @@
"babel-jest": "^24.9.0",
"babel-loader": "8.0.6",
"babel-plugin-named-asset-import": "^0.3.5",
"babel-preset-react-app": "^9.1.0",
"camelcase": "^5.3.1",
"case-sensitive-paths-webpack-plugin": "2.2.0",
"css-loader": "3.3.2",
Expand Down Expand Up @@ -79,7 +78,8 @@
"webpack": "4.41.2",
"webpack-dev-server": "3.9.0",
"webpack-manifest-plugin": "2.2.0",
"workbox-webpack-plugin": "4.3.1"
"workbox-webpack-plugin": "4.3.1",
"xometry-babel-preset-react-app": "^9.2.0"
},
"devDependencies": {
"react": "^16.12.0",
Expand Down
Loading