Giter Site home page Giter Site logo

harrysolovay / rescripts Goto Github PK

View Code? Open in Web Editor NEW
1.1K 9.0 59.0 27.07 MB

💥 Use the latest react-scripts with custom configurations for Babel, ESLint, TSLint, Webpack,... ∞

License: MIT License

JavaScript 69.20% HTML 16.70% CSS 2.11% TypeScript 11.73% Shell 0.27%
cra react react-scripts configuration customization

rescripts's Introduction

banner


Take control of your create-react-app project configurations. No ejecting, no custom react-scripts fork, no limitations.

Highlights

  • 🎯 create the perfect config with minimal effort

  • 🎩 take advantage of cutting-edge software that hasn't made its way into CRA

  • 🥳 draw from a library of open-source "rescripts"

  • 👽 compatibility with "rewires" designed for react-app-rewired

Guide

Background

CRA (create-react-app) provides a first-class React developer experience. For building single-page web apps, it's not only the fastest bootstrap––it's also the most carefully-curated, well-supported, and feature-fledged. There is a downside, however: in an effort to create stability and simplicity for beginners, its creators excluded many configuration options and newer technologies (such as Babel transformations based on early-stage TC39 proposals). CRA comes with an "eject" script which––once irreversibly run––allows customization of the "start", "build", and "test" scripts, along with their corresponding configurations. While this does allow you some DX freedom, it isn't always preferable; ejection makes it impossible to upgrade to new versions of react-scripts, and it exposes a lot of tedious, knarly-lookin' code. Rescripts is for developers who don't want to eject or worry about configuration, but still want to use cutting-edge tools.

Tim Arney's react-app-rewired was the first project to successfully tackle this problem. It offered a solution that led to many "rewires" (community-made plugins for simpler setup). But––when CRA 2.0 came around––there were some breaking changes. Not to mention, the react-app-rewired DX was something to be further simplified.

Rescripts tackles this same probem for CRA 2.0+ with several key DX differences. First off, it was designed to be more of a focal point for all non-standard configuration. The underlaying loader can handle deeply nested "rescripts" (conceptually similar to babel plugins), all of which can modify any CRA process. The tools used to transform configuration are more robust and flexible than its predecessor's (@rescripts/utilities), and should weather most updates. The API also exposes a middleware entry, so that you can track your configurations as they are transformed. It should also be noted that Rescripts is compatible with many Webpack rewires built for react-app-rewired.

If you like this framework, please tweet at @gaearon requesting an "everything-i-did-not-include" rescript!

Installation

Install @rescripts/cli as a dev dependency:

npm i -D @rescripts/cli

react-scripts@^2.1.2 requires you be using at least @rescripts/utilities^0.0.4 and @rescripts/cli^0.0.7

Install the rescript(s) you wish to use:

npm i -D @rescripts/rescript-env

@rescripts/rescript-env scans your package.json & project root for Babel, ESLint and TSLint configuration files. If present, these configurations will override the CRA defaults.

Basic Usage

1) Replace react-scripts calls with rescripts calls

package.json

{
  "name": "built-with-rescripts",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.6.1",
    "react-dom": "^16.6.1",
    "react-scripts": "2.1.1"
  }
  "devDependencies": {
    "@rescripts/cli": "^0.0.11",
    "@rescripts/rescript-env": "^0.0.10"
  }
  "scripts": {
-   "start": "react-scripts start",
+   "start": "rescripts start",
-   "build": "react-scripts build",
+   "build": "rescripts build",
-   "test": "react-scripts test",
+   "test": "rescripts test",
-   "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

2) Define a 'rescripts' field and specify which to use

package.json

{
  "name": "built-with-rescripts",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.6.1",
    "react-dom": "^16.6.1",
    "react-scripts": "2.1.1"
  }
  "devDependencies": {
    "@rescripts/cli": "^0.1.0"
  }
  "scripts": {
    "start": "rescripts start",
    "build": "rescripts build",
    "test": "rescripts test"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
+ "rescripts": [
+   "env"
+ ]
}

You could also––instead of placing this in your package.json––specify your "root rescript" in a root-level .rescriptsrc file (with whatever convention you prefer: .js, .json, or no extension.)

3) Use the newly-enabled feature(s)

In the case of @rescripts/rescript-env, you will now be able to use custom Babel, ESLint and TSLint configurations. Use any of the following conventions:

Babel: place config inside of a root-level .babelrc, .babelrc.js, .babelrc.json, or babel.config.js file, or inside of the babel field of your package.json

ESLint: place config inside of a root-level.eslintrc, .eslintrc.js, .eslintrc.json, or eslint.config.js file, or inside of the eslintConfig field of your package.json

TSLint: place config inside of a root-leveltslint.js or tslint.json file

4) Good practice with the env rescript

@rescripts/rescript-env actually installs 3 rescripts:

For an incrementally faster boot time, use these independently and actually specify their configurations. Aka...

.rescriptsrc

module.exports = [
  ['use-babel-config', '.babel.json'],
  ['use-tslint-config', 'tslint.json'],
]

Advanced Usage

Your root rescript should be an array of other rescripts. Some rescripts take in options and/or other parameters. Some do not. Some contain functions that transform your webpack config. Some contain transformations for any combination of processes (webpack, devServer and jest). Consider the following:

In this example, the root rescript makes reference to @rescripts/rescript-env. This rescript takes in no arguments, which means that it has to scan your project at every run.

module.exports = ['env']

Alternatively, you could use @rescripts/rescript-use-babel-config and @rescripts/rescript-use-eslint-config (or @rescripts/rescript-use-tslint-config if you prefer TypeScript):

module.exports = [
  ['use-babel-config', '.babelrc'],
  ['use-eslint-config', '.eslintrc'],
]

This example illustrates how arguments can be passed to a rescript by wrapping its reference inside of another array and adding the arguments as subsequent elements.

The eventual goal of Rescripts is to provide a single, simple interface for deep customizations:

.rescriptsrc.js

module.exports = [
  [
    'use-babel-config',
    {
      presets: ['react-app'],
      plugins: [
        'react-require',
        [
          'module-resolver',
          {
            root: '.',
            alias: {
              '~': './src',
            },
          },
        ],
      ],
    },
  ],
  [
    'use-eslint-config',
    {
      extends: ['react-app'],
      plugins: ['ramda'],
      rules: {
        'ramda/compose-pipe-style': 'error',
        'react/react-in-jsx-scope': 0,
      },
    },
  ],
]

Rescript Structure

Rescripts transform the default configurations used by the three main processes of CRA (webpack, its developement server, and test-running via Jest). Rescripts can do much more though, such as writing logs, caching files, commiting changes and triggering other processes.

A rescript can be...

an array of other rescripts

child-rescript.js

// define child rescript
module.exports = ['rescript-a', 'rescript-b', 'rescript-c']

parent-rescript.js

// use child rescript
module.exports = [require.resolve('path/to/child-rescript')]
a function that takes in and returns a webpack config

child-rescript.js

// define child rescript
module.exports = config => {
  const newConfig = doSomethingToTheConfig(config)
  return newConfig
},

parent-rescript.js

// use child rescript
module.exports = [require.resolve('path/to/child-rescript')]
an object containing (any combination of) `webpack`, `devServer`, and `jest` functions, which take in and return their respective configs

child-rescript.js

// define child rescript
module.exports = {
  webpack: config => {
    const newConfig = transformWebpackConfig(config)
    return newConfig
  },
  devServer: config => {
    const newConfig = transformDevServerConfig(config)
    return newConfig
  },
  jest: config => {
    const newConfig = transformJestConfig(config)
    return newConfig
  },
}

parent-rescript.js

// use child rescript
module.exports = [require.resolve('path/to/child-rescript')]
a function that takes in arguments and outputs a new rescript

child-rescript.js

// webpack only:
module.exports = options => config => {
  const newConfig = someTransformation(config, options)
  return newConfig
}

// or with multiple processes:
module.exports = (webpackArg, devServerArg, jestArg) => ({
  webpack: config => {
    const newConfig = transformWebpackConfig(config, webpackArg)
    return newConfig
  },
  devServer: config => {
    const newConfig = transformDevServerConfig(config, devServerArg)
    return newConfig
  },
  jest: config => {
    const newConfig = transformJestConfig(config, jestArg)
    return newConfig
  },
})

parent-rescript.js

// use child rescript

// webpack only:
module.exports = [
  [require.resolve('path/to/child-rescript'), 'some important webpack arg'],
]

// multiple processes:
module.exports = [
  [
    require.resolve('path/to/child-rescript'),
    'webpackArg',
    'devServerArg',
    'jestArg',
  ],
]
a combination of formats

child-rescript.js

// define child rescript
module.exports = [
  'some-rescripts',
  [
    'rescript-that-takes-args',
    {
      docsQuality: 'helpful?',
    },
  ],
  config => {
    const newConfig = doSomethingToTheConfig(config)
    return newConfig
  },
  [
    someArg => config => {
      const newConfig = doSomethingToTheConfig(config, someArg)
      return newConfig
    },
    'some argument',
  ],
]

parent-rescript.js

// use child rescript
module.exports = [require.resolve('path/to/child-rescript')]

Rescript SDK

The @rescripts/utilities package makes it far easier to interact with configuration, while also reducing code size and the amount of conflict you'd otherwise see from composing numerous rescripts. You can use the tools in this package to identify and transform parts of any configuration without an exact path.

npm i -D @rescripts/utilities

@rescripts/utilities comes with @rescripts/cli (so there's no need to install if you're already working on a rescripted project)

Reference

For FP-lovers: all of @rescripts/utilities' methods are curried, so feel free to call them in stages. Use Ramda's R.__ placeholder to reorder how arguments are pieced together in the resulting functions.

getPaths(predicate, scanTarget)

Recursively traverses your config (or any object for that matter) and returns an array of paths to any nodes that match the predicate. This is useful for editing parts of a config that may change location at runtime (ostensibly because of another rescript in the transformation pipeline).

usage example
const {getPaths} = require('@rescripts/utilities')

const isBabelLoader = inQuestion =>
  inQuestion && inQuestion.loader && inQuestion.loader.includes('babel-loader')

module.exports = config => {
  const babelLoaderPaths = getPaths(isBabelLoader, config)
  console.log(babelLoaderPaths) // [['module', 'rules', 2, 'oneOf', 1]]
  return config
}

edit(transform, paths, config)

Takes in a transformation function and the paths at which that function should be applied, along with the object on which to apply it.

usage example
const {getPaths, edit} = require('@rescripts/utilities')

module.exports = config => {
  const paths = getPaths(somePredicate, config)
  return edit(
    matchedSection => {
      // change something about the subsection
      const updatedSection = someTransformation(matchedSection)
      return updatedSection
    },
    paths,
    config,
  )
}

replace(replacement, paths, config)

Works the same as edit, only it takes in a replacement for the specified path rather than a transformation function.

usage example
const {getPaths, replace} = require('@rescripts/utilities')

module.exports = config => {
  const paths = getPaths(somePredicate, config)
  return replace('some replacement', paths, config)
}

remove(paths, config)

Takes in the specified path and the object for the path-specified deletion.

usage example
const {getPaths, remove} = require('@rescripts/utilities')

module.exports = config => {
  const paths = getPaths(somePredicate, config)
  return remove(paths, config)
}

getWebpackPlugin(constructorName, config)

Retrieve a plugin instance from the webpack config with the plugin's constructor name.

usage example
const {getWebpackPlugin} = require('@rescripts/utilities')

module.exports = config => {
  getWebpackPlugin('ForkTsCheckerWebpackPlugin', config) &&
    console.log('TypeScript enabled')
  return config
}

prependWebpackPlugin(pluginInstance, config)

Add a plugin instance to the first slot of the Webpack configuration's plugins array.

usage example
const {prependWebpackPlugin} = require('@rescripts/utilities')
const WebpackBuildNotifierPlugin = require('webpack-build-notifier')

module.exports = config => {
  return prependWebpackPlugin(
    new WebpackBuildNotifierPlugin({
      title: 'Rescripted App',
      logo: require.resolve('./public/icon.png'),
      suppressSuccess: true,
    }),
    config,
  )
}

// or simplified...

module.exports = prependWebpackPlugin(
  new WebpackBuildNotifierPlugin({
    title: 'Rescripted App',
    logo: require.resolve('./public/icon.png'),
    suppressSuccess: true,
  }),
)

appendWebpackPlugin(pluginInstance, config)

Add a plugin instance to the last slot of the Webpack configuration's plugins array.

usage example
const {appendWebpackPlugin} = require('@rescripts/utilities')
const WebpackBuildNotifierPlugin = require('webpack-build-notifier')

module.exports = config => {
  return appendWebpackPlugin(
    new WebpackBuildNotifierPlugin({
      title: 'Rescripted App',
      logo: require.resolve('./public/icon.png'),
      suppressSuccess: true,
    }),
    config,
  )
}

// or simplified...

module.exports = appendWebpackPlugin(
  new WebpackBuildNotifierPlugin({
    title: 'Rescripted App',
    logo: require.resolve('./public/icon.png'),
    suppressSuccess: true,
  }),
)

editWebpackPlugin(transform, constructorName, config)

Applies the transform function to the Webpack plugin whose constructor name is a match.

usage example
const {editWebpackPlugin} = require('@rescripts/utilities')

module.exports = config => {
  const edited = editWebpackPlugin(
    p => {
      p.someOption = 'changed'
      return p
    },
    'DefinePlugin',
    config,
  )
  return edited
}

// or simplified...

module.exports = editWebpackPlugin(
  p => {
    p.someOption = 'changed some option'
    return p
  },
  'DefinePlugin',
  config,
)

replaceWebpackPlugin(replacement, constructorName, config)

Replaces the matched plugin with another.

usage example
const {replaceWebpackPlugin} = require('@rescripts/utilities')
const WebpackPWAManifestPlugin = require('webpack-pwa-manifest')

module.exports = config => {
  const replaced = replaceWebpackPlugin(
    new WebpackPWAManifestPlugin({
      name: 'Rescripted App',
      short_name: 'Example',
      description: 'An example app that uses Rescripts',
      background_color: '#fff',
      crossorigin: 'use-credentials',
      icons: [
        {
          src: require.resolve('./public/icon.png'),
          sizes: [96, 128, 192, 256, 384, 512],
        },
      ],
    }),
    'ManifestPlugin',
    config,
  )
  return replaced
}

removeWebpackPlugin(constructorName, config)

Remove the matched plugin from your config.

usage example
const {removeWebpackPlugin} = require('@rescripts/utilities')

module.exports = config => {
  const withoutIgnorePlugin = removeWebpackPlugin('IgnorePlugin', config)
  return withoutIgnorePlugin
}

// or simplified ...

const {removeWebpackPlugin} = require('@rescripts/utilities')

module.exports = removeWebpackPlugin('IgnorePlugin', config)

Middleware

The term "middleware" in Rescripts describes a kind of rescript that runs between all other rescripts.

Let's say your stack of rescripts looks like this:

const logConfig = config => {
  console.log(config)
  return config
}

logConfig.isMiddleware = true

module.exports = [
  ['use-babel-config', '.babelrc'],
  ['use-tslint-config', 'tslint.json'],
  logConfig,
]

The execution order will be as follows:

  1. logConfig
  2. use-babel-config
  3. logConfig
  4. use-tslint-config
  5. logConfig

Don't be afraid to track data in the outer scope:

const equal = require('deep-equal')
let lastConfig = null

const logConfig = config => {
  const unchanged = equal(config, lastConfig)
  console.log(unchanged ? 'config unchanged' : 'config changed')
  lastConfig = config
  return config
}

logConfig.isMiddleware = true

module.exports = [
  ['use-babel-config', '.babelrc'],
  ['use-tslint-config', 'tslint.json'],
  logConfig,
]
In simplified form
const equal = require('deep-equal')
let lastConfig = null

module.exports = [
  ['use-babel-config', '.babelrc'],
  ['use-tslint-config', 'tslint.json'],
  Object.assign(
    config => {
      const unchanged = equal(config, lastConfig)
      console.log(unchanged ? 'config unchanged' : 'config changed')
      lastConfig = config
      return config
    },
    {isMiddleware: true},
  ),
]

We prefer to keep and mutate a lastConfig reference incase other middleware is applied before logConfig; middleware isn't spread around other middleware (this would be chaos), and yet middleware can transform what's passed to subsequent rescripts (including other middleware). This can get messy if you're not deliberate about your middleware's behavior.

Rescript Library

Miscellaneous

Thank you for checking out (and maybe even building software with) Rescripts. If you have any bug reports or feature ideas, please go ahead and file an issue. If you have any other questions, comments, etc., please reach out to [email protected].

Acknowledgements

Big shout out to...

This library has been released under the MIT license

SO DO WHATEVER THE $%#@ YOU WANT WITH IT!!!

rescripts's People

Contributors

amykyta avatar cacay avatar canercandan avatar cmdcolin avatar dependabot[bot] avatar garrettmaring avatar giraffesyo avatar harrysolovay avatar jonathantneal avatar kagamichan avatar linonetwo avatar mgcrea avatar negan1911 avatar swrobel avatar urakozz avatar whtsky avatar yurykozyrev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rescripts's Issues

How to add 'externals' setting

Hi, I try to add 'externals'

 externals: {
  AMap: 'AMap',
 }

result is

TypeError: reduce: list must be array or iterable

here is my problem code

.rescriptsrc.js

const {edit, getPaths} = require('@rescripts/utilities')

const matcher = inQuestion => 
  inQuestion.externals && inQuestion.externals.AMap

const transform = match => ({
  ...match,
  externals: {
    ...match.externals,
    AMap : 'AMap'
  },
})
module.exports = config => edit(
   ['use-babel-config', '.babelrc.json'],
   transform,
   getPaths(matcher, config),
   config
)

before i did it everything is ok

.rescriptsrc.js

module.exports =  [
  ['use-babel-config', '.babelrc.json'],
 ]

babelrc.json


{
  "presets": [
    "react-app"
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ]
  ]
}

Look like i still not code it right 🧐🧐🧐

Trouble installing @rescripts/rescript-use-babel-config

We need to add the emotion babel plugin to react-scripts test. The project's current .babelrc works fine for builds, but when used with rescripts test, it doesn't seem to be applied.

Running rescripts packages and react-scripts on latest versions. I did the following:

  1. Installed packages @rescripts/cli and @rescripts/rescript-use-babel-config
  2. Added package.json config: "rescripts": [["use-babel-config", ".babelrc"]]
  3. Run rescripts test

The error is related to the emotion component selector syntax, meaning the babel plugin is not in use. There are no errors or logs regarding the rescripts usage. Are there some ways to debug this package and see if the config is being applied or not?

I don't understand how to translate this code from react-app-rewired to rescripts:

I don't understand how to translate this code from react-app-rewired to rescripts:

  • config-overrides.js:
const { injectBabelPlugin } = require('react-app-rewired')

module.exports = function override (config, env) {
  config = injectBabelPlugin('graphql-tag', config)
  return config
}

Maybe it's just me but I really don't understand this simply problem.

How to?

Error in browser with `npm run start` (no errors in console)

Error in browser with npm run start (no errors in console):

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `Query`.
  • package.json:
...
  "devDependencies": {
    "@rescripts/cli": "0.0.10",
    "@rescripts/rescript-env": "0.0.5",
    "@rescripts/rescript-use-babel-config": "0.0.5",
}
  • .rescriptsrc.js:
module.exports = [['use-babel-config', '.babelrc']]
  • .babelrc.js:
module.exports = {
  presets: ['react-app'],
  plugins: ['graphql-tag']
}

If I use react-scripts start instead it works.

Continue compilation on tslint error with use-tslint-config

I was able to integrate CRA2 with tslint using rescripts-use-tslint-config.
However, my problem is that any error currently breaks the build instead of just being printed to the console. This behavior makes sense for CI pipeline, but is quite annoying during local development.

I'm wondering if it's possible to make this behavior configurable?

Thanks!

Trying to add ttypescript to webpack

I'm trying to get https://github.com/rimeto/ts-transform-optchain running in my typescript react app.
It needs https://github.com/cevek/ttypescript and therefore a webpack config:

{
    test: /\.(ts|tsx)$/,
    loader: require.resolve('ts-loader'),
    options: {
        compiler: 'ttypescript'
    }
}

Using #5 I came up with:
.rescriptsrc.js

module.exports = config => {
  config.modules.rules.unshift({
      test: /\.(ts|tsx)$/,
      use: [
          {
              loader: require.resolve('ts-loader'),
              options: {
                  compiler: 'ttypescript'
              }
          }
      ]
  });
  return config
};

Even if I add an explicit error to the file to verify that its executed, the app starts normally?!

My package.json:

{
  "name": "reactsandbox",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/polyfill": "^7.4.0",
    "@material-ui/core": "^3.9.3",
    "@material-ui/icons": "^3.0.2",
    "classnames": "latest",
    "prop-types": "latest",
    "proxy-polyfill": "^0.3.0",
    "react": "^16.8.6",
    "react-app-polyfill": "^0.2.2",
    "react-dom": "^16.8.6",
    "react-redux": "^6.0.1",
    "react-router-dom": "^5.0.0",
    "react-scripts": "2.1.8",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.0.2",
    "ts-transform-optchain": "^0.1.6"
  },
  "scripts": {
    "start": "BROWSER=none rescripts start",
    "build": "rescripts build",
    "test": "rescripts test",
    "eject": "rescripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie < 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "@rescripts/cli": "0.0.10",
    "@rescripts/rescript-env": "0.0.10",
    "@types/classnames": "^2.2.7",
    "@types/jest": "^24.0.11",
    "@types/node": "^11.12.2",
    "@types/react": "^16.8.10",
    "@types/react-dom": "^16.8.3",
    "@types/react-redux": "^7.0.6",
    "@types/react-router-dom": "^4.3.1",
    "@types/redux-logger": "^3.0.7",
    "ttypescript": "^1.5.6",
    "typescript": "^3.4.1"
  },
  "rescripts": [
    "env"
  ]
}

I cannot get it working, could you please help?

Incompatible with CRA default test command

I noticed a similar issue over here, and despite perhaps being repeat, I wanted to point out that if we're running a fullstack productionized app, it's likely that the default react-scripts test command is in use. With regard to extending webpack config to use plugins like directory-named-webpack-plugin, it's problematic that there's no way to mirror the overridden webpack config between the webpack vs. jest runtime environments we get from this module. Any thoughts on this? I just implemented rescripts in a large app and then had to pull it out when I found jest tests were failing due to pathing issues which are fine via directory-named-webpack-plugin but of course fail to run in jest.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

rescripts-cli can't find webpack config

Hi, I was faced the issue, when I set env in package.json

"rescripts": [
  "env"
]
Error: Cannot find module '/home/.../node_modules/react-scripts/config/webpack.config'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.resolve (internal/module.js:18:19)
    at module.exports (/home/.../node_modules/@rescripts/cli/patch.js:26:30)
    at args (/home/.../node_modules/@rescripts/cli/scripts/start.js:14:17)
    at forEach (/home/.../node_modules/ramda/src/forEach.js:45:5)
    at /home/.../node_modules/ramda/src/internal/_checkForMethod.js:22:72
    at f2 (/home/.../node_modules/ramda/src/internal/_curry2.js:29:14)
    at Object.<anonymous> (/home.../node_modules/@rescripts/cli/scripts/start.js:14:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)

Probably I have that result because a react-scripts folder doesn't contain webpack.config, but there are webpack.config.dev and webpack.config.prod.

image

Thanks,

p.s "react-scripts": "2.1.1" and "@rescripts/cli": "^0.0.7"

Webpack fails to compile

I'm getting this error when running npm start:

> rescripts start

Failed to compile.

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration should be an object.

I am using @rescripts/rescript-use-babel-config@rescripts/rescript-use-babel-config, followed the directions in the main README and put this in my package.json:

  "rescripts": [
    "use-babel-config"
  ]

and then added a .babelrc to root:

{
    "presets": ["stage-0"],
    "plugins": ["@babel/plugin-proposal-decorators"]
}

Not sure what's going wrong, and what config webpack is complaining about not being an object...
Additionally, I see in the readme for @rescripts/rescript-use-babel-config that for usage you say to put [["use-babel-config", ".babelrc"]] in .babelrc, but I'm not sure where that would go?

Add webpack plugins

To me, one of the main selling points of react-app-rewired is the ability to reconfigure webpack, for example by adding plugins in production mode.

How would i do this using rescripts?

Object config runs with an error

I'm trying to run rescript with an object in a child file (or directly in parent file)

module.exports = {
  webpack: config => config,
  devServer: config => config,
  jest: config => config
}

and in parent

module.exports = [require.resolve('path/to/child-rescript')]

Runs with an error

TypeError: Cannot convert undefined or null to object
at hasOwnProperty (<anonymous>)
  at _has (/Users/my-project/node_modules/ramda/src/internal/_has.js:2:42)
  at hasPath (/Users/my-project/node_modules/ramda/src/hasPath.js:35:9)
  at f2 (/Users/my-project/node_modules/ramda/src/internal/_curry2.js:29:14)
  at has (/Users/my-project/node_modules/ramda/src/has.js:32:10)
  at /Users/my-project/node_modules/ramda/src/internal/_curry2.js:22:18
  at f1 (/Users/my-project/node_modules/ramda/src/internal/_curry1.js:18:17)
  at _filter (/Users/my-project/node_modules/ramda/src/internal/_filter.js:7:9)
  at /Users/my-project/node_modules/ramda/src/filter.js:52:3
  at /Users/my-project/node_modules/ramda/src/internal/_dispatchable.js:41:15
  error Command failed with exit code 1.
  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command

Start script not working

The build script runs properly but the start scripts exits with status of 1 and there are no other errors. Below is the debug log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/T/Code/ld-ui/node_modules/.bin:/Users/T/.yarn/bin:/Users/T/.config/yarn/global/node_modules/.bin:/usr/local/opt/libpq/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/usr/local/opt/apr-util/bin:/usr/local/opt/openssl/bin:/usr/local/opt/apr/bin:/opt/local/bin:/opt/local/sbin:/Users/T/Library/Python/3.7/bin:/Users/T/Library/Python/2.7/bin:/Users/T/Library/Android/sdk//emulator:/Users/T/Library/Android/sdk//platform-tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin/:/opt/X11/bin
9 verbose lifecycle [email protected]~start: CWD: /Users/T/Code/ld-ui
10 silly lifecycle [email protected]~start: Args: [ '-c', 'rescripts start' ]
11 silly lifecycle [email protected]~start: Returned: code: 1 signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: rescripts start
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at EventEmitter.emit (events.js:214:7)
13 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at ChildProcess.emit (events.js:214:7)
13 verbose stack at maybeClose (internal/child_process.js:925:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/T/Code/ld-ui
16 verbose Darwin 18.5.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "start"
18 verbose node v8.10.0
19 verbose npm v6.7.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: rescripts start
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Configuring jest

I need to update the moduleFileExtensions recognized by Jest, as indicated by the error below. I just can't figure out how to do that with Rescripts. I have my .rescriptsrc.js file and I'm able to adjust weback config and use a custom eslintrc file, but not seeing how to tweak Jest config.

Cannot find module './quotes' from 'index.js'

    However, Jest was able to find:
        './quotes.scss'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

Add easy way to enable ESLint for TypeScript

There should be an option/package for enabling ESLint on .ts and .tsx files for those who do not want to use TSLint.

I managed to get this working with a custom config, but this should come pre-packaged. Here's the code (I would send a Pull Request but don't know where the best place to put this is):

const isESLintLoader = node =>
  node && node.loader && node.loader.includes('eslint-loader');

const isESLintRule = node =>
  node && node.use && node.use.some(isESLintLoader);

const enableEslintForTypeScript = config => {
  const paths = getPaths(isESLintRule, config);
  const test = /\.(js|mjs|jsx|ts|tsx)$/;
  return edit(
    matchedSection => {
      return Object.assign({}, matchedSection, { test: test });
    },
    paths,
    config
  );
};

This should come with some documentation since ESLint doesn't work with TypeScript out of the box. The following is a good start:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": "react-app"
}

You also need to install the packages used above:

npm install --save @typescript-eslint/parser @typescript-eslint/eslint-plugin

Finally, I'm not certain the code above covers everything. It matches what customize-cra. enableEslintTypescript() does, and it's the only place in the Webpack config that refers to ESLint as far as I can tell. Additionally, npm run build does print lint messages. But npm start doesn't log lint messages to the console unlike this claims.

Export rescripted webpack config for 3rd party tools

Hello, thanks for your work on this :)

I was wondering if there's a away to get the re-scripted configs output from rescripts as pure config for use in another tool?

react-app-rewired had this documented here.

I'm looking for something similar :)

Changing the entry field

How can I change the entry field in the config? Can't find enough usage examples to use rescripts right :(

--config parameter for CLI

Would it be possible to introduce option --conf to specify path to file with rescript config? Example usage: rescripts start --conf /path/to/config/rescript-config.js

My motivation:

I have multiple web projects using rescripts. In all projects, I have the same local configuration within .rescriptsrc.js file. Whenever I make change to one I update it in all repositories. It is similar for eslint, prettier configuration, etc. Therefore, I decided to extract it into web-scripts library which is collection of my custom scripts and common configuration on one place (something similar to https://github.com/kentcdodds/kcd-scripts)

Within my web-projects I "proxy" scripts in package.json to web-scripts, example:

scripts: {
  "start: "web-scripts start",
  "lint": "web-scripts lint",
  "format: "web-scripts format",
  ... 
}

Then web-scripts has the share configuration, so web-scripts executes

npx eslint --config ./web-scripts/configuration/eslint-cfg.js

for lint target. I would love to use similar approach for rescript :)

Is there is a possibility to add a custom script?

I read through the Readme and project looks awesome indeed.
I'm a maintainer of our own fork of react-scripts at Revolut and I'm really tired of keeping it in sync with upstream CRA. This one gives ability to basically reduce it all to one big Revolut rescript except one thing, there is no possibility to add custom script.
We have a script named format that runs prettier in a predefined manner.
So basically revolut-react-scripts format is possible like start, test, build etc., but with this one I think it's impossible to do so.
Or maybe I'm wrong? :)

If it's impossible that would be amazing to be able to do something like that.

CRA 2.1.2 merged webpack dev/prod config files

See this PR: #5722

Although it is an internal change of CRA 2.1.2, really a breaking change to users of rescripts.

I've submitted a PR: #7 to adopt this change.

If you want to support all versions of CRA 2, you shouldn't accept my PR because it just works with CRA 2.1.2

Adding `.babelrc` by-passes Babel entirely

What I did:

  1. npm i -D @rescripts/cli @rescripts/rescript-env
  2. Update package.json's scripts to use rescripts instead of react-scripts
  3. Add .rescriptsrc (containing: module.exports = [ "env"];)
  4. Add my own custom .babelrc

This is happening to me with [email protected], as well as [email protected].

A look at my package.json reveals:

"devDependencies": {
    "@rescripts/cli": "0.0.10",
    "@rescripts/rescript-env": "0.0.10"
  }

Expected:

Things to go as smoothly as they sometimes go in the occasional dream... ⭐⭐⭐⭐

Currently:

It appears that Babel has been entirely bypassed; It does not recognize jsx anymore...

The contents of the .babelrc file do not matter at all. No matter if my own customized version, if empty or if you copy some basic templates from the web, the result is always the same: babel gets bypassed entirely, like so:

Failed to compile.

./src/index.js
SyntaxError: /my-code/src/index.js: Unexpected token (18:16)

16 |
17 |
18 | ReactDOM.render(<Loading centered />, document.getElementById('root'));
     |                                 ^

The Twist

Things are working fine (except for legacy decorators, i.e. the CRA default babel config kicks in) if I remove my .babelrc file.

CRA3 support?

Does this package currently support CRA3 already or does it require changes? I couldn't find a definitive answer in the README/issues so thought I'd ask

[Feature]: Add react-scripts config paths modifier

I'm not sure if we can modify 'react-scripts/config/paths' exports before scripts running.

  • Custom tsconfig: require('react-scripts/config/paths').appTsConfig = path.resolve('tsconfig.dev.json')
  • Skip ForkTsCheckerWebpackPlugin: require('react-scripts/config/paths').appTsConfig += '.not-exists'

Hard-coded Config location

In my use-case, I want to re-package CRA with some different configuration and have the end-user use it in exactly the same way.

Currently the CLI looks for the config in two hardcoded places both of which I can't think of a way to monkey-patch without a visible config file or package field.

This partially leads to #14 - If I do have to expose the rescripts configuration, I'd like for it to be clean and easy to override.

My initial work has been to completely abstract configuration ala CRA, but have dotfile support.

After looking at this project, I like the rescripts api and having a package field with a pre-configured preset might be a good way to leave breadcrumbs to a potential best practice. But I worry about caveats such as the one I bring up in #14.

Setting environment variable PUBLIC_URL does not set PUBLIC_URL on build

Description

When using the PUBLIC_URL field in .env and then running npm run build the build succeeds but the PUBLIC_URL is not set. Seems that rescripts is ignoring the environmant variable. When setting homepage in package.json PUBLIC_URL is set. This works in a base react-scripts app as well as with react-scripts-rewired. But when moving to rescripts it no longer works.

@rescripts/[email protected]
@rescripts/[email protected]
[email protected]

Expected Behavior

URLs using the PUBLIC_URL variable should be set using the PUBLIC_URL environment variable.

Current Workaround

Add the url to your package.json as 'homepage'

Use Different Sass Loader

Hello, thanks for mantaining this project. Actually I'm using CRA 3.x with Typescript, and it uses the sass-loader as default for Sass processing.

How could I change it to use the yibn2008/fast-sass-loader?

I found the issue #18, but I don't know if it applies to this too.

Best regards.

DefinePlugins always provides undefined to the app but works within rescripts.

Title, basically.

I'm attempting to use the define plugin to pass a theme setting to the app so it can be built with either a dark or light theme, with the default being the light theme. This is how the DefinePlugin is setup (comments added to highlight the problem):

module.exports = [
  ['use-babel-config', '.babelrc'],
  ['use-eslint-config', '.eslintrc'],
  addLessLoader,
  appendWebpackPlugin(new DefinePlugin({
    'process.env.THEME': JSON.stringify(THEME) // app always gets undefined
  })),
  // ... snipped, but it's split chunks, compression, and uglify -- production only
  configLogger
]

The logger looks like this, and as shown above, runs last:

const configLogger = config => {
  console.dir(process.env.THEME)  // displays the correct value
  console.log('THEME IS:', THEME) // also displays the correct value
  return config
}

Console output:

Γ ****@**** Δ ~/****/ClientApp (ui/dark-theme)*
L Ω yarn build-dark
yarn run v1.16.0
$ set "NODE_ENV=production" && set "THEME=dark" && rescripts build
'dark'
THEME IS: dark
Creating an optimized production build...

So rescripts is definitely aware of the correct value.

I have also used this DefinePlugin config and got the same result:

  appendWebpackPlugin(new DefinePlugin({
    'process.env': {
      THEME: JSON.stringify(THEME) // app always gets undefined
    }
  }))

And the result for this version is also the same, except accessing it causes the app to crash:

  appendWebpackPlugin(new DefinePlugin({
    THEME: JSON.stringify(THEME) // app always gets undefined
  }))

While I would love to just use dotenv, this use-case is more of a customizable build setting and is not based on environment, so that's not going to cover my needs. I did try using dotenv to just provide the settings and pass them along, but the result was still the same.

Supplying the environment variable when running the build does make the configLogger function output the correct value, but still, it's undefined inside the app. When I build the app and run that version, it's also undefined there, so it's not a problem unique to just running it within the dev server, it also effects production builds.

I cannot load svg file

import { Avatar } from 'antd';
import PropTypes from 'prop-types';
import React from 'react';
import { ReactComponent as DeleteIcon } from './delete.svg';
import { ReactComponent as EditIcon } from './edit.svg';

export default function ViewModeEmployee({ data }) {
  return (
    <div className="editable-employee">
      <div className="editable-employee-name">
        <Avatar size={40} src={data.url} />
        {data.name}
      </div>
      <div className="editable-employee-phone">{data.phone}</div>

      <div className="editable-employee-working-time-view">
        10:00am - 7:00pm
      </div>
      <div className="editable-employee-controls">
        <EditIcon />
        <DeleteIcon />
      </div>
    </div>
  );
}

ViewModeEmployee.propTypes = {
  data: PropTypes.object.isRequired
};

As you can see, when I put <EditIcon /> and <DeleteIcon /> to the component, it shown me the error
image

react-app-rewire-define-plugin equivalent

Hi,

is there any way to define environment variable in webpack config?
something like :

const rewireDefinePlugin = require('react-app-rewire-define-plugin')

// Use `webpack.DefinePlugin` to add the version number from package.json
config = rewireDefinePlugin(config, env, {
  'process.env.VERSION': JSON.stringify(require('./package.json').version)
})

g.call is not a function

Getting this error when starting the dev server.

My config:

const configOverrides = {
  webpack: [
    ['use-eslint-config', '.eslintrc'],
    config => injectEmotionBabelPlugin(config),
  ],
  devServer: [
    config => addSettingsFolderToContentBase(config),
  ],
}

Excluding the ['use-eslint-config', '.eslintrc'] rescript solves the problem.

Cannot find tslint module when attempting to use this library on brand new app.

I created a new create-react-scripts typescript app using their documentation:
https://facebook.github.io/create-react-app/docs/adding-typescript

I then proceeded to add ts-lint via this rescripts library using the information provided in the wiki.
This is the full sample app (minus the node_modules folder): sample.zip
package.json:

{
  "name": "ideoclick-marketing",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "rescripts start",
    "build": "rescripts build"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "dependencies": {
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-scripts": "2.1.1"
  },
  "devDependencies": {
    "@rescripts/cli": "0.0.6",
    "@rescripts/rescript-env": "0.0.2",
    "@types/node": "^10.12.18",
    "@types/react": "^16.7.18",
    "@types/react-dom": "^16.0.11",
    "ts-lint": "^4.5.1",
    "tslint-config-prettier": "^1.17.0",
    "tslint-react": "^3.6.0",
    "typescript": "^3.2.2"
  }
}

.rescriptsrc:

module.exports = [
    ["use-tslint-config", "tslint.json"],
]

I also intentionally have a lint error in App.tsx due to the render method not having the public access modifier.

Upon running npm install and npm start, my expectation is that the create-react-app internals start up and the lint error would be outputted. However, what I'm actually receiving is this following error:
image
image

Can you please advise me on how to resolve this issue?

append instead of replace config

What I did:

  • install
  • create .rescriptsrc

.rescriptsrc

module.exports = [
  ['use-babel-config', 'babel.config.js']
];

babel.config.js

module.exports = {};

rescripts seem to "replace" the actual configuration, however what I want to achieve is to "append" something to the configuration, I just want to add babel-plugin-transform-remove-console.

When I run rescripts build, it throws

Creating an optimized production build...
Failed to compile.

./src/index.js
SyntaxError:

  15 |
  16 | render(
> 17 |   <ApolloProvider client={client}>
     |   ^
  18 |     <ThemeProvider theme={theme}>
  19 |       <MuiPickersUtilsProvider utils={DateFnsUtils}>
  20 |         <SnackbarProvider

TypeError: normalizeLoaded(...) is not a function

I'm trying yo use rescripts (coming from react-app-rewired) all latest versions but I got this error:

TypeError: normalizeLoaded(...) is not a function

  • package.json:
...
  "devDependencies": {
    "@rescripts/cli": "0.0.10",
    "@rescripts/rescript-env": "0.0.5",
    "@rescripts/rescript-use-babel-config": "0.0.5"
...
}
  • .rescriptsrc.js:
module.exports = [['use-babel-config', '.babelrc']]
  • .babelrc:
{
  "plugins": ["my-babel-plugin"]
}

Where am I wrong?

how to combine utilities and array configurations

Hi,

I am trying to combine multiple configuration in my .rescripts.js file

const { appendWebpackPlugin } = require("@rescripts/utilities");
const { DefinePlugin } = require("webpack");


module.exports = [
  appendWebpackPlugin(
    new DefinePlugin({
      "process.env.VERSION": JSON.stringify(require("./package.json").version)
    })
  ),
  [
    "use-babel-config",
    {
      presets: ["react-app"],
      plugins: [
        [
          "import",
          {
            libraryName: "antd",
            libraryDirectory: "es",
            style: "css" // true for less
          }
        ]
      ]
    }
  ]
];

but first part is which is reading version number from package.json file and add it as environment variable is not working.
these configs works individually but not together, can you please tell me what's the proper way of doing it?

Custom babel settings do not work

I am making an app with Create-React-App, electron, rescripts. The setup has previously been working, but now I need a custom babel config to add decorators and I can't get it to work.

.rescriptsrc.js:
module.exports = [ require.resolve("./webpack.config.js"), ["use-babel-config", ".babelrc"] ]

Was previously only the webpack.

webpack.config.js:
module.exports = config => { config.target = "electron-renderer" return config }

.babelrc:
{ "presets": ["react-app"], "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }], ["@babel/plugin-proposal-class-properties", { "loose": true }] ] }
I want to keep the CRA preset but add decorator support.

package.json:
"devDependencies": { "@babel/core": "^7.6.4", "@babel/plugin-proposal-class-properties": "^7.7.4", "@babel/plugin-proposal-decorators": "^7.7.4", "@rescripts/cli": "^0.0.11", "@rescripts/rescript-env": "^0.0.10", "@rescripts/rescript-use-babel-config": "^0.0.9", "@storybook/addon-actions": "^5.2.5", "@storybook/addon-links": "^5.2.5", "@storybook/addons": "^5.2.5", "@storybook/react": "^5.2.5", "babel-loader": "^8.0.6", "babel-preset-react-app": "^9.1.0", "concurrently": "^4.1.2", "cross-env": "^5.2.1", "electron": "^6.0.3", "electron-builder": "^21.2.0", "eslint-config-airbnb": "^18.0.1", "eslint-config-prettier": "^6.5.0", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-prettier": "^3.1.1", "prettier": "^1.19.1", "prettier-eslint": "^9.0.1", "prettier-eslint-cli": "^5.0.0", "prettier-stylelint": "^0.4.2", "stylelint": "^12.0.0", "stylelint-config-standard": "^19.0.0", "wait-on": "^3.3.0" }
Error output in electron:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of Icon.

If I remove the ["use-babel-config", ".babelrc"], then it works as normal but I cannot use decorators.
I think it is reading the .babelrc config because if I misstype something there I can crash the app. I have tried removing the "plugin-proposal-class-properties" but it does not make a difference.

Any ideas on something I might have missed?

please help...

i have trouble when i override config.. here is my code

module.exports = [
  [
    'use-babel-config',
    {
      presets: ['react-app'],
      plugins: [
        [
          'import',
          {
            libraryName: 'antd',
            libraryDirectory: 'es',
            style: true
          }
        ],
        'transform-decorators-legacy'
      ]
    }
  ],
  config => {
    console.log(config)
    RegExp.prototype.toJSON = RegExp.prototype.toString
    Function.prototype.toJSON = Function.prototype.toString
    fs.writeFileSync('webpack-config.json', JSON.stringify(newConfig, null, 2))
    return config
  }
]

i found that there is no log in terminal and not create the 'webpack-config.json' file, also i got no error...
it seems that the code was not ran ...
could you please help me to firgue out what should i do ...

"@rescripts/cli": "0.0.10",
"@rescripts/rescript-env": "0.0.5",
"react-scripts": "2.1.3",
.rescriptsrc.js at root dir

Error in path when loading stylelint config

Hi! I'm currently trying to load my .stylelintrc.json config but when I add it to .rescriptsrc.js it looks my .stylelintrc.json file 2 paths above the project folder

// .rescriptsrc.js
module.exports = [
  ['use-babel-config', '.babelrc'],
  ['use-stylelint-config', '.stylelintrc.json']
]
// .stylelint.json
{
  "processors": ["stylelint-processor-styled-components"],
  "extends": [
    "stylelint-config-recommended",
    "stylelint-config-styled-components"
  ],
  "rules": {
      "no-descending-specificity": null
    }
}

Thanks in advance!

Rescripts test isnt using babel config

When I run my testing suite with rescripts test, the tests don't seem to pickup on my .babelrc file:

{
  "presets": ["react-app"],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators", {
        "legacy": true,
      }
    ],
    [
      "babel-plugin-named-asset-import",
      {
        "loaderMap": {
          "svg": {
            "ReactComponent": "@svgr/webpack?-prettier,-svgo![path]",
          },
        },
      },
    ],
  ],
}

As such I get this error: SyntaxError: /path/to/src/stores/index.js: Support for the experimental syntax 'decorators-legacy' isn't currently enabled because i'm using decorators, but the babel plugin should resolve this.

The UI works fine when I run rescripts start

.rescriptsrc.js:

module.exports = ['env'];

Uninstallation - is it easy as I think it is?

If I want to uninstall recripts, can I simply run yarn remove rescripts and then change the calls to yarn start, etc., in the package.json?

There isn't an explicit description of this in the documentation which I think would be very helpful. In my case, being able to uninstall this package without any hitches makes me much more likely to add it in the first place!

If the procedure above is the case I'm happy to make a PR!

Is there a way to use rescripts with tsc?

I've came to this package because react-scripts-ts became deprecated and I want custom eslint config and don't want to compile TypeScript with Babel. I've followed the steps described in README (installed rescripts, created .rescriptsrc, added use-eslint-config), but the build failed with

>yarn start
Failed to compile.

./src/registerServiceWorker.ts
  Line 12:  Parsing error: The keyword 'const' is reserved

Yes, I use const in my code. And I want to. How do I get the program to compile with tsc again?

Custom rescripts receive no parameters

I'm trying to transform my webpack config (after creating a standard CRA2 app) following the structure from the README but the first parameter (which I assume is meant to be the webpack config) is undefined.

Here's a trivial example of my .rescriptsrc file:

module.exports = [
  [(config) => {
    console.log(config);
    return config;
  }]
];

Expected output:

{
  mode: 'development',
  devtool: 'cheap-module-source-map',
  ...
}

Actual output:

undefined

Am I doing something wrong?

I was specifically trying to follow the a function that takes in and returns a webpack config section. Moving the function to a file like in the example (obviously) has no effect either.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.