devk
226
4
Mix

Different output files with different configs

Posted 1 month ago by devk

What's the best way to compile 2 JS files that require different configs? Namely, my server config requires some additional config options from my regular frontend config.

This is basically what I'm trying to do (spoiler, it doesn't work because the 2nd config is applied to the client side as well:

const sharedConfig = {
  // Shared config
};

mix
  .setPublicPath('./')
  .webpackConfig(sharedConfig)
  .copy('src/static', './public')
  .ts('src/ts/index.tsx', 'public/js/app.js');

mix
  .setPublicPath('./')
  .webpackConfig({
    ...sharedConfig,
    externals: [nodeExternals()],
    node: {
      __dirname: false,
    },
  })
  .ts('node/server.tsx', './server.js');

Please sign in or create an account to participate in this conversation.