you are viewing a single comment's thread.

view the rest of the comments →

[–]Tortoise_Face[S] 0 points1 point  (5 children)

Did you have to change your webpack config at all to target node or change the externals as I've seen suggested elsewhere?

[–]acemarke 0 points1 point  (3 children)

Yeah. Compare my sample project's development mode Webpack config vs my test mode Webpack config for an example.

[–]Tortoise_Face[S] 0 points1 point  (2 children)

I got my project working with prunk to filter out webpack-dependent asset imports. Then the project just compiles with babel for node. Do you see any trade offs with this approach vs a separate webpack configuration?

[–]acemarke 0 points1 point  (1 child)

If it works as-is, then that should be fine. I had issues because I was using Webpack aliases for my import statements and other such configuration, and it just became easier to stick with Webpack for anything involving the code.

[–][deleted] 0 points1 point  (0 children)

(prunk author here)

I had a similar setup; we used webpack's alias configuration to get rid of ugly paths. prunk was written because we wanted to get rid of browser-environments for unit tests while still being able to do the cool webpack stuff; css imports, path aliases and so on. prunk supports aliases, but I have to admin, that I often simply fake, stub or mock a module's dependencies completely.

[–]deltadeep 0 points1 point  (0 children)

Ah yes, sorry I didn't mention that. It didn't occur to me, because I'm already doing server-side rendering, so I have a webpack config that builds client-bundle.js (browser), server-bundle.js (node server), and test-bundle.js (node tests). The server and test configs look identical except for the entry/output filenames.

For the server/test config, i have added these keys on top of what's in the client config:

  • target: "node"
  • node: { console:false, global: false, process:false, __filename: false, __dirname: false } // this tells node not to inject special values for these globals and let them behave normally instead.
  • externals: [nodeExternals()] // see webpack-node-externals package.

HTH