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

correct configuration for files that do not exist in development #42

Open
dagda1 opened this issue Feb 21, 2018 · 0 comments
Open

correct configuration for files that do not exist in development #42

dagda1 opened this issue Feb 21, 2018 · 0 comments

Comments

@dagda1
Copy link

dagda1 commented Feb 21, 2018

I have the following code:

    const configureProduction = (app: any) => {
      const clientStats = require('./stats.json');
      const serverRender = require('./server.js').default;
      const publicPath = '/';
      const outputPath = join(__dirname, '.');
    
      app.use(publicPath, express.static(outputPath));
      app.use(
        serverRender({
          clientStats,
          outputPath
        })
      );
    
      app.set('views', join(__dirname, 'views'));
    };
    
    const app = express();
    
    if (process.env.NODE_ENV === 'development') {
      configureDevelopment(app);
    } else {
      configureProduction(app);
    }

When running in development, the configureProduction function is not called but I get the following webpack errors:

ERROR in ./src/index.tsx Module not found: Error: Can't resolve
'./server.js' in
'/Users/paulcowan/projects/cuttingedge/packages/website/src' @
./src/index.tsx 38:23-45 @ multi ./src/index

ERROR in ./src/index.tsx Module not found: Error: Can't resolve
'./stats.json' in
'/Users/paulcowan/projects/cuttingedge/packages/website/src' @
./src/index.tsx 37:22-45 @ multi ./src/index

My nodeExternals is set like this:

    externals: [
      nodeExternals({
        modulesDir: path.join(process.cwd(), '../../node_modules'),
        whitelist: [
          isDevelopment ? 'webpack/hot/poll?300' : null,
          './stats.json',
          './server.js',
          /\.(eot|woff|woff2|ttf|otf)$/,
          /\.(svg|png|jpg|jpeg|gif|ico)$/,
          /\.(mp4|mp3|ogg|swf|webp)$/,
          /\.(css|scss|sass|sss|less)$/
        ].filter(x => x)
      })
    ],

How can I configure this correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant