Create React App V2 - Multiple entry pointsLoop inside React JSXWhat do these three dots in React do?Programmatically navigate using react routerwebpack public folder for imagesWebpack fails to find module dirsAccessing files outside the entry pointRails controller to return a whole react appprerender.io with create-react-app on nginx not serving static files from project root rather pre-render root. Also react-snapshot not workingCreate-react-app with express backend works locally but routing incorrect when deployed to herokuCreate-react-app build failing on heroku when using absolute paths

Independent, post-Brexit Scotland - would there be a hard border with England?

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

Can an isometry leave entropy invariant?

Pressure inside an infinite ocean?

How I can I roll a number of non-digital dice to get a random number between 1 and 150?

Would glacier 'trees' be plausible?

Shantae Dance Matching

What does this colon mean? It is not labeling, it is not ternary operator

Why was the battle set up *outside* Winterfell?

What was the first instance of a "planet eater" in sci-fi?

How do I overfit?

BOOM! Perfect Clear for Mr. T

Upside-Down Pyramid Addition...REVERSED!

Why did the Apollo 13 crew extend the LM landing gear?

I drew a randomly colored grid of points with tikz, how do I force it to remember the first grid from then on?

How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?

What is a smasher?

Would the Disguise Self spell be able to reveal hidden birthmarks/tattoos (of the person they're disguised as) to a character?

What is the most remote airport from the center of the city it supposedly serves?

How do I tell my manager that his code review comment is wrong?

Can hackers enable the camera after the user disabled it?

How to display a value with zenity?

Point of the the Dothraki's attack in GoT S8E3?

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?



Create React App V2 - Multiple entry points


Loop inside React JSXWhat do these three dots in React do?Programmatically navigate using react routerwebpack public folder for imagesWebpack fails to find module dirsAccessing files outside the entry pointRails controller to return a whole react appprerender.io with create-react-app on nginx not serving static files from project root rather pre-render root. Also react-snapshot not workingCreate-react-app with express backend works locally but routing incorrect when deployed to herokuCreate-react-app build failing on heroku when using absolute paths






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel.



I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/.



I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something.



Efter ejecting CRA, these are the paths I've changed/added to paths.js:



module.exports = 
appBuild: resolveApp('build/app'),
appPublic: resolveApp('public/app'),
appHtml: resolveApp('public/app/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/app'),
appSrc: resolveApp('src'),
adminIndexJs: resolveModule(resolveApp, 'src/admin'),
adminSrc: resolveApp('src'),
adminPublic: resolveApp('public/admin'),
adminHtml: resolveApp('public/admin/index.html'),
;


I've added these entry points to webpack:



 entry: 
app: [
isEnvDevelopment &&
require.resolve('react-dev-utils/webpackHotDevClient'),
paths.appIndexJs,
].filter(Boolean),
admin: [
isEnvDevelopment &&
require.resolve('react-dev-utils/webpackHotDevClient'),
paths.adminIndexJs,
].filter(Boolean)
,
output:
path: isEnvProduction ? paths.appBuild : undefined,
pathinfo: isEnvDevelopment,
filename: isEnvProduction
? 'static/js/[name].[contenthash:8].js'
: isEnvDevelopment && 'static/js/bundle.js',
chunkFilename: isEnvProduction
? 'static/js/[name].[contenthash:8].chunk.js'
: isEnvDevelopment && 'static/js/[name].chunk.js',
publicPath: publicPath,
devtoolModuleFilenameTemplate: isEnvProduction
? info =>
path
.relative(paths.appSrc, info.absoluteResourcePath)
.replace(/\/g, '/')
: isEnvDevelopment &&
(info => path.resolve(info.absoluteResourcePath).replace(/\/g, '/')),
,


I've modified HtmlWebpackPlugin like so:



 new HtmlWebpackPlugin(
Object.assign(
,

inject: true,
template: paths.appHtml,
filename: paths.appPublic,
,
isEnvProduction
?
minify:
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
,

: undefined
)
),
new HtmlWebpackPlugin(
Object.assign(
,

inject: true,
template: paths.adminHtml,
filename: paths.adminPublic,
,
isEnvProduction
?
minify:
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
,

: undefined
)
),


And modified webpack Dev Server:



historyApiFallback: 
disableDotRule: true,
rewrites: [
from: /^/admin.html/, to: '/build/admin/index.html' ,
]
,


My file structure is like follows:



.
+-- _src
| +-- app.js
| +-- admin.js
| +-- _app
| +-- App.js
| +-- _admin
| +-- App.js
| +-- _shared
| +-- serviceWorker.js
+-- _public
| +-- _app
| +-- index.html
| +-- manifest.json
| +-- _admin
| +-- index.html
| +-- manifest.json


I would like my build folder to contain an app folder and an admin folder with the 2 separate SPA's in them.



When I run yarn start it doesn't throw any errors and says Compiled successfully! however its only partially compiled the app and not the admin app, no js has been compiled or added to the app either.



yarn build does throw an error and a half compiled app, no admin app. This is the error:



yarn run v1.12.3
$ node scripts/build.js
Creating an optimized production build...
Failed to compile.

EISDIR: illegal operation on a directory, open
'foo/bar/public/app'


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


In the build folder it had created much this before it exit:



.
+-- _static
| +-- _css
| +-- _js
| +-- _media
| +-- logo.5d5d9eef.svg
+-- precache-manifest.a9c066d088142837bfe429bd3779ebfa.js
+-- service-worker.js
+-- asset-manifest.json
+-- manifest.json


Does anyone know what I am missing out to make this work correctly?










share|improve this question






























    0















    I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel.



    I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/.



    I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something.



    Efter ejecting CRA, these are the paths I've changed/added to paths.js:



    module.exports = 
    appBuild: resolveApp('build/app'),
    appPublic: resolveApp('public/app'),
    appHtml: resolveApp('public/app/index.html'),
    appIndexJs: resolveModule(resolveApp, 'src/app'),
    appSrc: resolveApp('src'),
    adminIndexJs: resolveModule(resolveApp, 'src/admin'),
    adminSrc: resolveApp('src'),
    adminPublic: resolveApp('public/admin'),
    adminHtml: resolveApp('public/admin/index.html'),
    ;


    I've added these entry points to webpack:



     entry: 
    app: [
    isEnvDevelopment &&
    require.resolve('react-dev-utils/webpackHotDevClient'),
    paths.appIndexJs,
    ].filter(Boolean),
    admin: [
    isEnvDevelopment &&
    require.resolve('react-dev-utils/webpackHotDevClient'),
    paths.adminIndexJs,
    ].filter(Boolean)
    ,
    output:
    path: isEnvProduction ? paths.appBuild : undefined,
    pathinfo: isEnvDevelopment,
    filename: isEnvProduction
    ? 'static/js/[name].[contenthash:8].js'
    : isEnvDevelopment && 'static/js/bundle.js',
    chunkFilename: isEnvProduction
    ? 'static/js/[name].[contenthash:8].chunk.js'
    : isEnvDevelopment && 'static/js/[name].chunk.js',
    publicPath: publicPath,
    devtoolModuleFilenameTemplate: isEnvProduction
    ? info =>
    path
    .relative(paths.appSrc, info.absoluteResourcePath)
    .replace(/\/g, '/')
    : isEnvDevelopment &&
    (info => path.resolve(info.absoluteResourcePath).replace(/\/g, '/')),
    ,


    I've modified HtmlWebpackPlugin like so:



     new HtmlWebpackPlugin(
    Object.assign(
    ,

    inject: true,
    template: paths.appHtml,
    filename: paths.appPublic,
    ,
    isEnvProduction
    ?
    minify:
    removeComments: true,
    collapseWhitespace: true,
    removeRedundantAttributes: true,
    useShortDoctype: true,
    removeEmptyAttributes: true,
    removeStyleLinkTypeAttributes: true,
    keepClosingSlash: true,
    minifyJS: true,
    minifyCSS: true,
    minifyURLs: true,
    ,

    : undefined
    )
    ),
    new HtmlWebpackPlugin(
    Object.assign(
    ,

    inject: true,
    template: paths.adminHtml,
    filename: paths.adminPublic,
    ,
    isEnvProduction
    ?
    minify:
    removeComments: true,
    collapseWhitespace: true,
    removeRedundantAttributes: true,
    useShortDoctype: true,
    removeEmptyAttributes: true,
    removeStyleLinkTypeAttributes: true,
    keepClosingSlash: true,
    minifyJS: true,
    minifyCSS: true,
    minifyURLs: true,
    ,

    : undefined
    )
    ),


    And modified webpack Dev Server:



    historyApiFallback: 
    disableDotRule: true,
    rewrites: [
    from: /^/admin.html/, to: '/build/admin/index.html' ,
    ]
    ,


    My file structure is like follows:



    .
    +-- _src
    | +-- app.js
    | +-- admin.js
    | +-- _app
    | +-- App.js
    | +-- _admin
    | +-- App.js
    | +-- _shared
    | +-- serviceWorker.js
    +-- _public
    | +-- _app
    | +-- index.html
    | +-- manifest.json
    | +-- _admin
    | +-- index.html
    | +-- manifest.json


    I would like my build folder to contain an app folder and an admin folder with the 2 separate SPA's in them.



    When I run yarn start it doesn't throw any errors and says Compiled successfully! however its only partially compiled the app and not the admin app, no js has been compiled or added to the app either.



    yarn build does throw an error and a half compiled app, no admin app. This is the error:



    yarn run v1.12.3
    $ node scripts/build.js
    Creating an optimized production build...
    Failed to compile.

    EISDIR: illegal operation on a directory, open
    'foo/bar/public/app'


    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


    In the build folder it had created much this before it exit:



    .
    +-- _static
    | +-- _css
    | +-- _js
    | +-- _media
    | +-- logo.5d5d9eef.svg
    +-- precache-manifest.a9c066d088142837bfe429bd3779ebfa.js
    +-- service-worker.js
    +-- asset-manifest.json
    +-- manifest.json


    Does anyone know what I am missing out to make this work correctly?










    share|improve this question


























      0












      0








      0








      I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel.



      I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/.



      I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something.



      Efter ejecting CRA, these are the paths I've changed/added to paths.js:



      module.exports = 
      appBuild: resolveApp('build/app'),
      appPublic: resolveApp('public/app'),
      appHtml: resolveApp('public/app/index.html'),
      appIndexJs: resolveModule(resolveApp, 'src/app'),
      appSrc: resolveApp('src'),
      adminIndexJs: resolveModule(resolveApp, 'src/admin'),
      adminSrc: resolveApp('src'),
      adminPublic: resolveApp('public/admin'),
      adminHtml: resolveApp('public/admin/index.html'),
      ;


      I've added these entry points to webpack:



       entry: 
      app: [
      isEnvDevelopment &&
      require.resolve('react-dev-utils/webpackHotDevClient'),
      paths.appIndexJs,
      ].filter(Boolean),
      admin: [
      isEnvDevelopment &&
      require.resolve('react-dev-utils/webpackHotDevClient'),
      paths.adminIndexJs,
      ].filter(Boolean)
      ,
      output:
      path: isEnvProduction ? paths.appBuild : undefined,
      pathinfo: isEnvDevelopment,
      filename: isEnvProduction
      ? 'static/js/[name].[contenthash:8].js'
      : isEnvDevelopment && 'static/js/bundle.js',
      chunkFilename: isEnvProduction
      ? 'static/js/[name].[contenthash:8].chunk.js'
      : isEnvDevelopment && 'static/js/[name].chunk.js',
      publicPath: publicPath,
      devtoolModuleFilenameTemplate: isEnvProduction
      ? info =>
      path
      .relative(paths.appSrc, info.absoluteResourcePath)
      .replace(/\/g, '/')
      : isEnvDevelopment &&
      (info => path.resolve(info.absoluteResourcePath).replace(/\/g, '/')),
      ,


      I've modified HtmlWebpackPlugin like so:



       new HtmlWebpackPlugin(
      Object.assign(
      ,

      inject: true,
      template: paths.appHtml,
      filename: paths.appPublic,
      ,
      isEnvProduction
      ?
      minify:
      removeComments: true,
      collapseWhitespace: true,
      removeRedundantAttributes: true,
      useShortDoctype: true,
      removeEmptyAttributes: true,
      removeStyleLinkTypeAttributes: true,
      keepClosingSlash: true,
      minifyJS: true,
      minifyCSS: true,
      minifyURLs: true,
      ,

      : undefined
      )
      ),
      new HtmlWebpackPlugin(
      Object.assign(
      ,

      inject: true,
      template: paths.adminHtml,
      filename: paths.adminPublic,
      ,
      isEnvProduction
      ?
      minify:
      removeComments: true,
      collapseWhitespace: true,
      removeRedundantAttributes: true,
      useShortDoctype: true,
      removeEmptyAttributes: true,
      removeStyleLinkTypeAttributes: true,
      keepClosingSlash: true,
      minifyJS: true,
      minifyCSS: true,
      minifyURLs: true,
      ,

      : undefined
      )
      ),


      And modified webpack Dev Server:



      historyApiFallback: 
      disableDotRule: true,
      rewrites: [
      from: /^/admin.html/, to: '/build/admin/index.html' ,
      ]
      ,


      My file structure is like follows:



      .
      +-- _src
      | +-- app.js
      | +-- admin.js
      | +-- _app
      | +-- App.js
      | +-- _admin
      | +-- App.js
      | +-- _shared
      | +-- serviceWorker.js
      +-- _public
      | +-- _app
      | +-- index.html
      | +-- manifest.json
      | +-- _admin
      | +-- index.html
      | +-- manifest.json


      I would like my build folder to contain an app folder and an admin folder with the 2 separate SPA's in them.



      When I run yarn start it doesn't throw any errors and says Compiled successfully! however its only partially compiled the app and not the admin app, no js has been compiled or added to the app either.



      yarn build does throw an error and a half compiled app, no admin app. This is the error:



      yarn run v1.12.3
      $ node scripts/build.js
      Creating an optimized production build...
      Failed to compile.

      EISDIR: illegal operation on a directory, open
      'foo/bar/public/app'


      error Command failed with exit code 1.
      info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


      In the build folder it had created much this before it exit:



      .
      +-- _static
      | +-- _css
      | +-- _js
      | +-- _media
      | +-- logo.5d5d9eef.svg
      +-- precache-manifest.a9c066d088142837bfe429bd3779ebfa.js
      +-- service-worker.js
      +-- asset-manifest.json
      +-- manifest.json


      Does anyone know what I am missing out to make this work correctly?










      share|improve this question
















      I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel.



      I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/.



      I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something.



      Efter ejecting CRA, these are the paths I've changed/added to paths.js:



      module.exports = 
      appBuild: resolveApp('build/app'),
      appPublic: resolveApp('public/app'),
      appHtml: resolveApp('public/app/index.html'),
      appIndexJs: resolveModule(resolveApp, 'src/app'),
      appSrc: resolveApp('src'),
      adminIndexJs: resolveModule(resolveApp, 'src/admin'),
      adminSrc: resolveApp('src'),
      adminPublic: resolveApp('public/admin'),
      adminHtml: resolveApp('public/admin/index.html'),
      ;


      I've added these entry points to webpack:



       entry: 
      app: [
      isEnvDevelopment &&
      require.resolve('react-dev-utils/webpackHotDevClient'),
      paths.appIndexJs,
      ].filter(Boolean),
      admin: [
      isEnvDevelopment &&
      require.resolve('react-dev-utils/webpackHotDevClient'),
      paths.adminIndexJs,
      ].filter(Boolean)
      ,
      output:
      path: isEnvProduction ? paths.appBuild : undefined,
      pathinfo: isEnvDevelopment,
      filename: isEnvProduction
      ? 'static/js/[name].[contenthash:8].js'
      : isEnvDevelopment && 'static/js/bundle.js',
      chunkFilename: isEnvProduction
      ? 'static/js/[name].[contenthash:8].chunk.js'
      : isEnvDevelopment && 'static/js/[name].chunk.js',
      publicPath: publicPath,
      devtoolModuleFilenameTemplate: isEnvProduction
      ? info =>
      path
      .relative(paths.appSrc, info.absoluteResourcePath)
      .replace(/\/g, '/')
      : isEnvDevelopment &&
      (info => path.resolve(info.absoluteResourcePath).replace(/\/g, '/')),
      ,


      I've modified HtmlWebpackPlugin like so:



       new HtmlWebpackPlugin(
      Object.assign(
      ,

      inject: true,
      template: paths.appHtml,
      filename: paths.appPublic,
      ,
      isEnvProduction
      ?
      minify:
      removeComments: true,
      collapseWhitespace: true,
      removeRedundantAttributes: true,
      useShortDoctype: true,
      removeEmptyAttributes: true,
      removeStyleLinkTypeAttributes: true,
      keepClosingSlash: true,
      minifyJS: true,
      minifyCSS: true,
      minifyURLs: true,
      ,

      : undefined
      )
      ),
      new HtmlWebpackPlugin(
      Object.assign(
      ,

      inject: true,
      template: paths.adminHtml,
      filename: paths.adminPublic,
      ,
      isEnvProduction
      ?
      minify:
      removeComments: true,
      collapseWhitespace: true,
      removeRedundantAttributes: true,
      useShortDoctype: true,
      removeEmptyAttributes: true,
      removeStyleLinkTypeAttributes: true,
      keepClosingSlash: true,
      minifyJS: true,
      minifyCSS: true,
      minifyURLs: true,
      ,

      : undefined
      )
      ),


      And modified webpack Dev Server:



      historyApiFallback: 
      disableDotRule: true,
      rewrites: [
      from: /^/admin.html/, to: '/build/admin/index.html' ,
      ]
      ,


      My file structure is like follows:



      .
      +-- _src
      | +-- app.js
      | +-- admin.js
      | +-- _app
      | +-- App.js
      | +-- _admin
      | +-- App.js
      | +-- _shared
      | +-- serviceWorker.js
      +-- _public
      | +-- _app
      | +-- index.html
      | +-- manifest.json
      | +-- _admin
      | +-- index.html
      | +-- manifest.json


      I would like my build folder to contain an app folder and an admin folder with the 2 separate SPA's in them.



      When I run yarn start it doesn't throw any errors and says Compiled successfully! however its only partially compiled the app and not the admin app, no js has been compiled or added to the app either.



      yarn build does throw an error and a half compiled app, no admin app. This is the error:



      yarn run v1.12.3
      $ node scripts/build.js
      Creating an optimized production build...
      Failed to compile.

      EISDIR: illegal operation on a directory, open
      'foo/bar/public/app'


      error Command failed with exit code 1.
      info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


      In the build folder it had created much this before it exit:



      .
      +-- _static
      | +-- _css
      | +-- _js
      | +-- _media
      | +-- logo.5d5d9eef.svg
      +-- precache-manifest.a9c066d088142837bfe429bd3779ebfa.js
      +-- service-worker.js
      +-- asset-manifest.json
      +-- manifest.json


      Does anyone know what I am missing out to make this work correctly?







      reactjs webpack create-react-app






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 12:46







      Richard

















      asked Mar 22 at 22:36









      RichardRichard

      105




      105






















          2 Answers
          2






          active

          oldest

          votes


















          0














          This one is working for the latest react version v2
          but it only works for the build(npm run build); running npm start in react folder (client) would have a bug



          https://github.com/chiKaRau/git-reactv2-express-multiple-entry-point



          other sources
          http://houserqu.com/2018/04/26/create-react-app-%E9%85%8D%E7%BD%AE%E5%A4%9A%E9%A1%B5%E9%9D%A2/



          https://www.jianshu.com/p/951287ce12c0



          http://imshuai.com/create-react-app-multiple-entry-points/






          share|improve this answer






























            0














            I realised that setting filename in HTMLWebpackPlugin to appPublic or adminPublic was incorrect and it should be app/index.html admin/index.html.



            However where I would like 2 separate folders in the build folder, one for the app and the other for the admin app, using this method requires more complexity because there is no entry variable in webpack that you can use to set the destination path. For example I would need to be able to do something like [entry]/static/js/[name].[contenthash:8].chunk.js. I think one way to do this would be to use Webpack MultiCompiler.



            However rather than doing this this I've passed the entry point as an environment variable in package.json, adding REACT_APP_ENTRY= like so:



             "scripts": 
            "start-app": "REACT_APP_ENTRY=app node scripts/start.js",
            "build-app": "REACT_APP_ENTRY=app node scripts/build.js",
            "start-admin": "REACT_APP_ENTRY=admin node scripts/start.js",
            "build-admin": "REACT_APP_ENTRY=admin node scripts/build.js",
            "test": "node scripts/test.js"
            ,


            In start.js I added const isApp = process.env.REACT_APP_ENTRY === 'app'; at the top:



            'use strict';

            process.env.BABEL_ENV = 'development';
            process.env.NODE_ENV = 'development';

            const isApp = process.env.REACT_APP_ENTRY === 'app';


            And updated where the port is being set, this is so I can run both development servers at the same time without a clash:



            const DEFAULT_PORT = parseInt(process.env.PORT, 10) || (isApp ? 3000 : 3001);
            const HOST = process.env.HOST || '0.0.0.0';


            Then at the top of paths.js add const isApp = process.env.REACT_APP_ENTRY === 'app';:



            const envPublicUrl = process.env.PUBLIC_URL;
            const isApp = process.env.REACT_APP_ENTRY === 'app';


            And finally update the paths depending on the env variable set:



            module.exports = 
            dotenv: resolveApp('.env'),
            appPath: resolveApp('.'),
            appBuild: isApp ? resolveApp('build/app') : resolveApp('build/admin'),
            appPublic: isApp ? resolveApp('public/app') : resolveApp('public/admin'),
            appHtml: isApp ? resolveApp('public/app/index.html') : resolveApp('public/admin/index.html'),
            appIndexJs: isApp ? resolveModule(resolveApp, 'src/app') : resolveModule(resolveApp, 'src/admin'),
            appPackageJson: resolveApp('package.json'),
            appSrc: resolveApp('src'),
            appTsConfig: resolveApp('tsconfig.json'),
            yarnLockFile: resolveApp('yarn.lock'),
            testsSetup: resolveModule(resolveApp, 'src/setupTests'),
            proxySetup: resolveApp('src/setupProxy.js'),
            appNodeModules: resolveApp('node_modules'),
            publicUrl: getPublicUrl(resolveApp('package.json')),
            servedPath: getServedPath(resolveApp('package.json')),
            ;


            I think this method as well as being far simpler is superior for this use case as it allows the flexibility to compile only the app or only the admin rather than forcing you to compile both when only one has been changed. I can run both yarn start-app and yarn start-admin at the same time with the separate apps running on different ports.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308657%2fcreate-react-app-v2-multiple-entry-points%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              This one is working for the latest react version v2
              but it only works for the build(npm run build); running npm start in react folder (client) would have a bug



              https://github.com/chiKaRau/git-reactv2-express-multiple-entry-point



              other sources
              http://houserqu.com/2018/04/26/create-react-app-%E9%85%8D%E7%BD%AE%E5%A4%9A%E9%A1%B5%E9%9D%A2/



              https://www.jianshu.com/p/951287ce12c0



              http://imshuai.com/create-react-app-multiple-entry-points/






              share|improve this answer



























                0














                This one is working for the latest react version v2
                but it only works for the build(npm run build); running npm start in react folder (client) would have a bug



                https://github.com/chiKaRau/git-reactv2-express-multiple-entry-point



                other sources
                http://houserqu.com/2018/04/26/create-react-app-%E9%85%8D%E7%BD%AE%E5%A4%9A%E9%A1%B5%E9%9D%A2/



                https://www.jianshu.com/p/951287ce12c0



                http://imshuai.com/create-react-app-multiple-entry-points/






                share|improve this answer

























                  0












                  0








                  0







                  This one is working for the latest react version v2
                  but it only works for the build(npm run build); running npm start in react folder (client) would have a bug



                  https://github.com/chiKaRau/git-reactv2-express-multiple-entry-point



                  other sources
                  http://houserqu.com/2018/04/26/create-react-app-%E9%85%8D%E7%BD%AE%E5%A4%9A%E9%A1%B5%E9%9D%A2/



                  https://www.jianshu.com/p/951287ce12c0



                  http://imshuai.com/create-react-app-multiple-entry-points/






                  share|improve this answer













                  This one is working for the latest react version v2
                  but it only works for the build(npm run build); running npm start in react folder (client) would have a bug



                  https://github.com/chiKaRau/git-reactv2-express-multiple-entry-point



                  other sources
                  http://houserqu.com/2018/04/26/create-react-app-%E9%85%8D%E7%BD%AE%E5%A4%9A%E9%A1%B5%E9%9D%A2/



                  https://www.jianshu.com/p/951287ce12c0



                  http://imshuai.com/create-react-app-multiple-entry-points/







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 29 at 21:55









                  user47103user47103

                  62212




                  62212























                      0














                      I realised that setting filename in HTMLWebpackPlugin to appPublic or adminPublic was incorrect and it should be app/index.html admin/index.html.



                      However where I would like 2 separate folders in the build folder, one for the app and the other for the admin app, using this method requires more complexity because there is no entry variable in webpack that you can use to set the destination path. For example I would need to be able to do something like [entry]/static/js/[name].[contenthash:8].chunk.js. I think one way to do this would be to use Webpack MultiCompiler.



                      However rather than doing this this I've passed the entry point as an environment variable in package.json, adding REACT_APP_ENTRY= like so:



                       "scripts": 
                      "start-app": "REACT_APP_ENTRY=app node scripts/start.js",
                      "build-app": "REACT_APP_ENTRY=app node scripts/build.js",
                      "start-admin": "REACT_APP_ENTRY=admin node scripts/start.js",
                      "build-admin": "REACT_APP_ENTRY=admin node scripts/build.js",
                      "test": "node scripts/test.js"
                      ,


                      In start.js I added const isApp = process.env.REACT_APP_ENTRY === 'app'; at the top:



                      'use strict';

                      process.env.BABEL_ENV = 'development';
                      process.env.NODE_ENV = 'development';

                      const isApp = process.env.REACT_APP_ENTRY === 'app';


                      And updated where the port is being set, this is so I can run both development servers at the same time without a clash:



                      const DEFAULT_PORT = parseInt(process.env.PORT, 10) || (isApp ? 3000 : 3001);
                      const HOST = process.env.HOST || '0.0.0.0';


                      Then at the top of paths.js add const isApp = process.env.REACT_APP_ENTRY === 'app';:



                      const envPublicUrl = process.env.PUBLIC_URL;
                      const isApp = process.env.REACT_APP_ENTRY === 'app';


                      And finally update the paths depending on the env variable set:



                      module.exports = 
                      dotenv: resolveApp('.env'),
                      appPath: resolveApp('.'),
                      appBuild: isApp ? resolveApp('build/app') : resolveApp('build/admin'),
                      appPublic: isApp ? resolveApp('public/app') : resolveApp('public/admin'),
                      appHtml: isApp ? resolveApp('public/app/index.html') : resolveApp('public/admin/index.html'),
                      appIndexJs: isApp ? resolveModule(resolveApp, 'src/app') : resolveModule(resolveApp, 'src/admin'),
                      appPackageJson: resolveApp('package.json'),
                      appSrc: resolveApp('src'),
                      appTsConfig: resolveApp('tsconfig.json'),
                      yarnLockFile: resolveApp('yarn.lock'),
                      testsSetup: resolveModule(resolveApp, 'src/setupTests'),
                      proxySetup: resolveApp('src/setupProxy.js'),
                      appNodeModules: resolveApp('node_modules'),
                      publicUrl: getPublicUrl(resolveApp('package.json')),
                      servedPath: getServedPath(resolveApp('package.json')),
                      ;


                      I think this method as well as being far simpler is superior for this use case as it allows the flexibility to compile only the app or only the admin rather than forcing you to compile both when only one has been changed. I can run both yarn start-app and yarn start-admin at the same time with the separate apps running on different ports.






                      share|improve this answer



























                        0














                        I realised that setting filename in HTMLWebpackPlugin to appPublic or adminPublic was incorrect and it should be app/index.html admin/index.html.



                        However where I would like 2 separate folders in the build folder, one for the app and the other for the admin app, using this method requires more complexity because there is no entry variable in webpack that you can use to set the destination path. For example I would need to be able to do something like [entry]/static/js/[name].[contenthash:8].chunk.js. I think one way to do this would be to use Webpack MultiCompiler.



                        However rather than doing this this I've passed the entry point as an environment variable in package.json, adding REACT_APP_ENTRY= like so:



                         "scripts": 
                        "start-app": "REACT_APP_ENTRY=app node scripts/start.js",
                        "build-app": "REACT_APP_ENTRY=app node scripts/build.js",
                        "start-admin": "REACT_APP_ENTRY=admin node scripts/start.js",
                        "build-admin": "REACT_APP_ENTRY=admin node scripts/build.js",
                        "test": "node scripts/test.js"
                        ,


                        In start.js I added const isApp = process.env.REACT_APP_ENTRY === 'app'; at the top:



                        'use strict';

                        process.env.BABEL_ENV = 'development';
                        process.env.NODE_ENV = 'development';

                        const isApp = process.env.REACT_APP_ENTRY === 'app';


                        And updated where the port is being set, this is so I can run both development servers at the same time without a clash:



                        const DEFAULT_PORT = parseInt(process.env.PORT, 10) || (isApp ? 3000 : 3001);
                        const HOST = process.env.HOST || '0.0.0.0';


                        Then at the top of paths.js add const isApp = process.env.REACT_APP_ENTRY === 'app';:



                        const envPublicUrl = process.env.PUBLIC_URL;
                        const isApp = process.env.REACT_APP_ENTRY === 'app';


                        And finally update the paths depending on the env variable set:



                        module.exports = 
                        dotenv: resolveApp('.env'),
                        appPath: resolveApp('.'),
                        appBuild: isApp ? resolveApp('build/app') : resolveApp('build/admin'),
                        appPublic: isApp ? resolveApp('public/app') : resolveApp('public/admin'),
                        appHtml: isApp ? resolveApp('public/app/index.html') : resolveApp('public/admin/index.html'),
                        appIndexJs: isApp ? resolveModule(resolveApp, 'src/app') : resolveModule(resolveApp, 'src/admin'),
                        appPackageJson: resolveApp('package.json'),
                        appSrc: resolveApp('src'),
                        appTsConfig: resolveApp('tsconfig.json'),
                        yarnLockFile: resolveApp('yarn.lock'),
                        testsSetup: resolveModule(resolveApp, 'src/setupTests'),
                        proxySetup: resolveApp('src/setupProxy.js'),
                        appNodeModules: resolveApp('node_modules'),
                        publicUrl: getPublicUrl(resolveApp('package.json')),
                        servedPath: getServedPath(resolveApp('package.json')),
                        ;


                        I think this method as well as being far simpler is superior for this use case as it allows the flexibility to compile only the app or only the admin rather than forcing you to compile both when only one has been changed. I can run both yarn start-app and yarn start-admin at the same time with the separate apps running on different ports.






                        share|improve this answer

























                          0












                          0








                          0







                          I realised that setting filename in HTMLWebpackPlugin to appPublic or adminPublic was incorrect and it should be app/index.html admin/index.html.



                          However where I would like 2 separate folders in the build folder, one for the app and the other for the admin app, using this method requires more complexity because there is no entry variable in webpack that you can use to set the destination path. For example I would need to be able to do something like [entry]/static/js/[name].[contenthash:8].chunk.js. I think one way to do this would be to use Webpack MultiCompiler.



                          However rather than doing this this I've passed the entry point as an environment variable in package.json, adding REACT_APP_ENTRY= like so:



                           "scripts": 
                          "start-app": "REACT_APP_ENTRY=app node scripts/start.js",
                          "build-app": "REACT_APP_ENTRY=app node scripts/build.js",
                          "start-admin": "REACT_APP_ENTRY=admin node scripts/start.js",
                          "build-admin": "REACT_APP_ENTRY=admin node scripts/build.js",
                          "test": "node scripts/test.js"
                          ,


                          In start.js I added const isApp = process.env.REACT_APP_ENTRY === 'app'; at the top:



                          'use strict';

                          process.env.BABEL_ENV = 'development';
                          process.env.NODE_ENV = 'development';

                          const isApp = process.env.REACT_APP_ENTRY === 'app';


                          And updated where the port is being set, this is so I can run both development servers at the same time without a clash:



                          const DEFAULT_PORT = parseInt(process.env.PORT, 10) || (isApp ? 3000 : 3001);
                          const HOST = process.env.HOST || '0.0.0.0';


                          Then at the top of paths.js add const isApp = process.env.REACT_APP_ENTRY === 'app';:



                          const envPublicUrl = process.env.PUBLIC_URL;
                          const isApp = process.env.REACT_APP_ENTRY === 'app';


                          And finally update the paths depending on the env variable set:



                          module.exports = 
                          dotenv: resolveApp('.env'),
                          appPath: resolveApp('.'),
                          appBuild: isApp ? resolveApp('build/app') : resolveApp('build/admin'),
                          appPublic: isApp ? resolveApp('public/app') : resolveApp('public/admin'),
                          appHtml: isApp ? resolveApp('public/app/index.html') : resolveApp('public/admin/index.html'),
                          appIndexJs: isApp ? resolveModule(resolveApp, 'src/app') : resolveModule(resolveApp, 'src/admin'),
                          appPackageJson: resolveApp('package.json'),
                          appSrc: resolveApp('src'),
                          appTsConfig: resolveApp('tsconfig.json'),
                          yarnLockFile: resolveApp('yarn.lock'),
                          testsSetup: resolveModule(resolveApp, 'src/setupTests'),
                          proxySetup: resolveApp('src/setupProxy.js'),
                          appNodeModules: resolveApp('node_modules'),
                          publicUrl: getPublicUrl(resolveApp('package.json')),
                          servedPath: getServedPath(resolveApp('package.json')),
                          ;


                          I think this method as well as being far simpler is superior for this use case as it allows the flexibility to compile only the app or only the admin rather than forcing you to compile both when only one has been changed. I can run both yarn start-app and yarn start-admin at the same time with the separate apps running on different ports.






                          share|improve this answer













                          I realised that setting filename in HTMLWebpackPlugin to appPublic or adminPublic was incorrect and it should be app/index.html admin/index.html.



                          However where I would like 2 separate folders in the build folder, one for the app and the other for the admin app, using this method requires more complexity because there is no entry variable in webpack that you can use to set the destination path. For example I would need to be able to do something like [entry]/static/js/[name].[contenthash:8].chunk.js. I think one way to do this would be to use Webpack MultiCompiler.



                          However rather than doing this this I've passed the entry point as an environment variable in package.json, adding REACT_APP_ENTRY= like so:



                           "scripts": 
                          "start-app": "REACT_APP_ENTRY=app node scripts/start.js",
                          "build-app": "REACT_APP_ENTRY=app node scripts/build.js",
                          "start-admin": "REACT_APP_ENTRY=admin node scripts/start.js",
                          "build-admin": "REACT_APP_ENTRY=admin node scripts/build.js",
                          "test": "node scripts/test.js"
                          ,


                          In start.js I added const isApp = process.env.REACT_APP_ENTRY === 'app'; at the top:



                          'use strict';

                          process.env.BABEL_ENV = 'development';
                          process.env.NODE_ENV = 'development';

                          const isApp = process.env.REACT_APP_ENTRY === 'app';


                          And updated where the port is being set, this is so I can run both development servers at the same time without a clash:



                          const DEFAULT_PORT = parseInt(process.env.PORT, 10) || (isApp ? 3000 : 3001);
                          const HOST = process.env.HOST || '0.0.0.0';


                          Then at the top of paths.js add const isApp = process.env.REACT_APP_ENTRY === 'app';:



                          const envPublicUrl = process.env.PUBLIC_URL;
                          const isApp = process.env.REACT_APP_ENTRY === 'app';


                          And finally update the paths depending on the env variable set:



                          module.exports = 
                          dotenv: resolveApp('.env'),
                          appPath: resolveApp('.'),
                          appBuild: isApp ? resolveApp('build/app') : resolveApp('build/admin'),
                          appPublic: isApp ? resolveApp('public/app') : resolveApp('public/admin'),
                          appHtml: isApp ? resolveApp('public/app/index.html') : resolveApp('public/admin/index.html'),
                          appIndexJs: isApp ? resolveModule(resolveApp, 'src/app') : resolveModule(resolveApp, 'src/admin'),
                          appPackageJson: resolveApp('package.json'),
                          appSrc: resolveApp('src'),
                          appTsConfig: resolveApp('tsconfig.json'),
                          yarnLockFile: resolveApp('yarn.lock'),
                          testsSetup: resolveModule(resolveApp, 'src/setupTests'),
                          proxySetup: resolveApp('src/setupProxy.js'),
                          appNodeModules: resolveApp('node_modules'),
                          publicUrl: getPublicUrl(resolveApp('package.json')),
                          servedPath: getServedPath(resolveApp('package.json')),
                          ;


                          I think this method as well as being far simpler is superior for this use case as it allows the flexibility to compile only the app or only the admin rather than forcing you to compile both when only one has been changed. I can run both yarn start-app and yarn start-admin at the same time with the separate apps running on different ports.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 30 at 12:45









                          RichardRichard

                          105




                          105



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308657%2fcreate-react-app-v2-multiple-entry-points%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript