Giter Site home page Giter Site logo

richardo2016 / react-app-rewire-multiple-entry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from derek-hu/react-app-rewire-multiple-entry

0.0 0.0 0.0 149 KB

Support Multiple Entry in Create-React-App

License: MIT License

JavaScript 26.42% TypeScript 73.58%

react-app-rewire-multiple-entry's Introduction

@richardo2016/react-app-rewire-multiple-entry

NPM version

React App Rewire Multiple Entry lets you configure multiple entry in Create React App v1, v2 and v3 without ejecting.

Usage

Add React App Rewire Multiple Entry to your Rewired React app:

npm install @richardo2016/react-app-rewire-multiple-entry --save-dev

Next, add React App Rewire Multiple Entry to config-overrides.js in your React app directory:

Basic Usage

// config-overrides.js

const multipleEntry = require('@richardo2016/react-app-rewire-multiple-entry')([
  {
    entry: 'src/entry/landing.js',
    template: 'public/landing.html',
    outPath: '/landing.html'
  }
]);

module.exports = {
  webpack: function(config, env) {
    multipleEntry.addMultiEntry(config);
    return config;
  }
};

Work with customize-cra

// config-overrides.js

const multipleEntry = require('@richardo2016/react-app-rewire-multiple-entry')([
  {
    entry: 'src/entry/landing.js',
    template: 'public/landing.html',
    outPath: '/landing.html'
  }
]);

const {
  // addBundleVisualizer,
  override,
  overrideDevServer
} = require('customize-cra');

module.exports = {
  webpack: override(
    multipleEntry.addMultiEntry
    // addBundleVisualizer()
  )
};

More Examples

// config-overrides.js

const multipleEntry = require('@richardo2016/react-app-rewire-multiple-entry')([
  {
    // Webpack extra entry
    entry: 'src/entry/standard.js',
    // HTML template used in plugin HtmlWebpackPlugin
    template: 'src/entry/standard.html',
    // The file to write the HTML to. You can specify a subdirectory
    outPath: '/entry/standard.html'
    // Visit: http[s]://localhost:3000/entry/standard.html
  },
  {
    entry: 'src/entry/login.js',
    // if [template] is empty, Default value: `public/index.html`
    // template: 'public/index.html',
    outPath: 'public/login.html'
    // Visit: http[s]://localhost:3000/public/login.html
  },
  {
    entry: 'src/entry/404.js',
    template: 'public/404.html'
    // if [outPath] is empty, calculated by `path.relative(process.cwd(), template)` --> `public/404.html`
    // outPath: '/public/404.html'
    // Visit: http[s]://localhost:3000/public/404.html
  },
  {
    entry: 'src/entry/home.js'
    // Default value: `public/index.html`
    // template: 'public/index.html',
    // Calculated by `path.relative(process.cwd(), template)` --> `public/index.html`
    // outPath: '/public/index.html'
    // Visit: http[s]://localhost:3000/public/index.html
  }
]);

module.exports = {
  webpack: function(config, env) {
    multipleEntry.addMultiEntry(config);
    return config;
  }
};

API

Options

You can pass a array of entry configuration options to @richardo2016/react-app-rewire-multiple-entry, the entry in the array has attributes below:

  • entry [Required] Webpack entry JS file. Throw error when empty.
  • hash [Optional] Whether use hash in output name for this entry.
  • template [Optional] HTML template used in plugin HtmlWebpackPlugin. Default value: public/index.html.
  • outPath: [Optional] The file wirte the HTML to. You can specify a subdirectory. If empty, it will be calculated by path.relative(process.cwd(), template)

Method

  • addMultiEntry Inject settings for multiple entry in webpack config

That’s it! Now you can control mulitple entry, enjoy coding!


License

MIT

NOTICE This repo is forked from 's Derek-Hu/react-app-rewire-multiple-entry, which version without any LICENSE.

react-app-rewire-multiple-entry's People

Contributors

derek-hu avatar richardo2016 avatar puckey avatar

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.