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

Feature request: export scripts (start/test/build) as functions #1434

Closed
tuchk4 opened this issue Jan 24, 2017 · 3 comments
Closed

Feature request: export scripts (start/test/build) as functions #1434

tuchk4 opened this issue Jan 24, 2017 · 3 comments

Comments

@tuchk4
Copy link
Contributor

tuchk4 commented Jan 24, 2017

TLDR
very very simple example:

const start = require('react-scripts/scripts/start');
const config = require('react-scripts/config/weback.config.dev');
start(config);

An same for test / build.

Change webpack config  —  add plugins and change entry point

I have two situation when I have to do this:

Another case - start or build Create React Application from another node script. Right now it is possible with spawn:

const start = spawn('node', ['neutron-server/start.js'], {
  cwd: path.join(__dirname, '..'),
  stdio: 'inherit'
});

With suggest feature this should be more beautiful.


There is the workaround how to implement it. I wrote about it at Why I love Create React App

Add build:custom to npm-scripts:

"scripts": {
  "build:custom": "node scripts/webpack"
}

And then create scripts/webpack.js:

const webpack = require('react-scripts/node_modules/webpack');
const craWebpackConfig = require('react-scripts/config/webpack.config.prod');
const OfflinePlugin = require('offline-plugin');

const config = {
  ...craWebpackConfig,
  plugins: [
     ...craWebpackConfig.plugins,
     new OfflinePlugin()
  ],
  entry: [
    craWebpackConfig.entry[0], // pollyfils
    path.resolve('src', 'awesome-component.js')
  ],
  output: {
    ...craWebpackConfig.output,
    path: path.resolve('pf-build')
  }
};
webpack(config).run(function(err, stats) {
  if (err !== null) {
    console.log('done');
  } else {
    console.log(err);
  }
});

There is just webpack config extending, not react-scripts build. And there are no beautiful console logs, comparison of the build sizes and other react-scripts build command features.
With suggested feature - it is possible to use start/test/build scripts but with custom configs.

@gaearon
Copy link
Contributor

gaearon commented Jan 24, 2017

We don't plan to expose Webpack config. That CRA uses Webpack is an implementation detail. If something that fits our use case better comes along, we will switch to that instead, and we don't want this to be a burden to our users. Therefore we don't intend to make Webpack usage explicit until you eject.

@tuchk4 tuchk4 closed this as completed Jan 24, 2017
@tuchk4
Copy link
Contributor Author

tuchk4 commented Jan 24, 2017

I expected such your answer :)
But anyway decided to request the feature. At medium post Why I love Create React App I tried to describe why I love CRA and why I don't want to eject.

@gaearon
Copy link
Contributor

gaearon commented Jan 24, 2017

I'm happy to consider feature requests on case by case basis. For example I think we could enable OfflinePlugin by default. I just don't know enough about it so I have been postponing this until a later stage.

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants