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

Override paths.js values in razzle.config.js #714

Closed
KevinMind opened this issue Jul 28, 2018 · 12 comments
Closed

Override paths.js values in razzle.config.js #714

KevinMind opened this issue Jul 28, 2018 · 12 comments

Comments

@KevinMind
Copy link

I would like to move my server dir into the root so my filesystem would look like this.

-/src
-server
-...etc.

Digging in razzle, it seems that babel and webpack are getting location of code from

module.exports = {
  dotenv: resolveApp('.env'),
  appPath: resolveApp('.'),
  appBuild: resolveApp('build'),
  appBuildPublic: resolveApp('build/public'),
  appManifest: resolveApp('build/assets.json'),
  appPublic: resolveApp('public'),
  appNodeModules: resolveApp('node_modules'),
  appSrc: resolveApp('src'),
  appPackageJson: resolveApp('package.json'),
  appServerIndexJs: resolveApp('src'),
  appClientIndexJs: resolveApp('src/client'),
  testsSetup: resolveApp('src/setupTests.js'),
  appBabelRc: resolveApp('.babelrc'),
  appEslintRc: resolveApp('.eslintrc'),
  appRazzleConfig: resolveApp('razzle.config.js'),
  nodePaths: nodePaths,
  ownPath: resolveOwn('.'),
  ownNodeModules: resolveOwn('node_modules'),
  publicUrl: getPublicUrl(resolveApp('package.json')),
  servedPath: getServedPath(resolveApp('package.json')),
};

The only issue is, because the values are hard coded, I can't override them.

I've come up with a work around by copypasting the resolveApp function from razzle to razle.config.js

const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);

and looping through rules and depending on environment and configuration I replace the include property with my custom path, like so...

      appConfig.module.rules.map(rule => {
        if (rule.include && rule.test) {
          rule.include = [
            resolveApp('server'),
            resolveApp('src'),
          ];
        }
      })

This feels really hacky though. Would it be possible to abstract the hard coded values in paths.js to environment variables or expose them in the createConfig function so that I can change the paths whenever I want?

I'd be happy to work on this if it seems like a good idea, but maybe there's a solution for this already that I'm missing. Please help :)

@stale
Copy link

stale bot commented Sep 26, 2018

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

@stale stale bot added the stale label Sep 26, 2018
@olehreznichenko
Copy link
Contributor

Well. I moved my server to new server folder inside src
And then in razzle.config.js edit config for the server

config.entry.pop()
config.entry.push('./src/server')

It works fine but seems like after this debugging (--inspect) nodejs is broken

@stale stale bot removed the stale label Sep 27, 2018
@stale
Copy link

stale bot commented Nov 26, 2018

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

@stale stale bot added the stale label Nov 26, 2018
@stale
Copy link

stale bot commented Dec 3, 2018

ProBot automatically closed this due to inactivity. Holler if this is a mistake, and we'll re-open it.

@stale stale bot closed this as completed Dec 3, 2018
@brianjd
Copy link

brianjd commented Jan 29, 2019

This issue shouldn't have been closed.

@ambar ambar mentioned this issue Feb 28, 2019
@jaredpalmer jaredpalmer reopened this Apr 16, 2019
@stale stale bot removed the stale label Apr 16, 2019
@novembrea
Copy link

I'm also using workarounds to set different application directory, it's a pretty large project that hosts API code in the same root directory, and 'src' is really ambiguous.

@stale stale bot added the stale label Aug 4, 2019
@antoniomaia
Copy link

@nvma Can you please provide an example to set different application directory? Thanks!

@stale stale bot removed the stale label Oct 21, 2019
@stale stale bot added the stale label Dec 20, 2019
@mikestopcontinues
Copy link

I think this is a pretty important issue. I'd be willing to submit a PR ASAP if we can come up with a list of the core directories that should be configurable. Off the bat, I'd say: build, src for client, src for server, and public.

@brianjd
Copy link

brianjd commented Apr 3, 2020

I was able to resolve it in my razzle / webpack configuration.

@fivethreeo
Copy link
Collaborator

On my radar, have sort of a plan 😀

@pseudo-su
Copy link
Contributor

pseudo-su commented Jun 6, 2020

In case it's useful to someone else I recently had to do this in razzle.config.js and it seems to work

const defaultOptions = {
  server: null,
  client: null,
};

function modifyEntryPoints(baseConfig, env, webpack, userOptions = {}) {
  const options = { ...defaultOptions, ...userOptions };
  const webpackConfig = { ...baseConfig };

  const { client, server } = options;
  /* This is required to rename the entry points instead of using the defaults */
  if (env.target === "node" && server) {
    webpackConfig.entry = [server];
  }
  if (env.target !== "node" && client) {
    webpackConfig.entry.client = client;
  }

  return webpackConfig;
}


module.exports = {
  plugins: [
    {
      func: modifyEntryPoints,
      options: {
        server: path.join(__dirname, "./src/docker-server"),
        client: path.join(__dirname, "./src/docker-client"),
      },
    },
  ]
};

@fivethreeo
Copy link
Collaborator

fixed in dev

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

No branches or pull requests

9 participants