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

Pre-compile mongoose/browser #7219

Closed
vkarpov15 opened this issue Nov 5, 2018 · 4 comments
Closed

Pre-compile mongoose/browser #7219

vkarpov15 opened this issue Nov 5, 2018 · 4 comments
Labels
developer-experience This issue improves error messages, debugging, or reporting

Comments

@vkarpov15
Copy link
Collaborator

So people don't have to merge their webpack config with Mongoose's recommended config. Re: discussion from #6826 (comment)

@vkarpov15 vkarpov15 added the developer-experience This issue improves error messages, debugging, or reporting label Nov 5, 2018
@vkarpov15 vkarpov15 added this to the 5.x Unprioritized milestone Nov 5, 2018
@saiichihashimoto
Copy link
Contributor

Here's a really good guide on how to do this:

https://webpack.js.org/guides/author-libraries/

@captaincaius
Copy link
Contributor

So in my monorepo project I just finally got around to setting up a child package that depends on mongoose and builds it with webpack, and I was thinking about PRing something, but I realized my goals probably aren't the same as other people's and this would warrant more discussion first. I'm not sure how it's possible to satisfy everyone's needs with this.

To illustrate what I mean, I'll paste the webpack config I'm using and why...

const paths = require('path');
  
module.exports = {
  entry: require.resolve('mongoose/browser.js'),
  output: {
    filename: 'index.js',
    path: paths.resolve(__dirname, ''),
    libraryTarget: 'commonjs2',
  },
  externals: [
    /^node_modules\/.+$/
  ],
  module: {
    rules: [
      {
        include: [
          /\/mongoose\//i,
          /\/kareem\//i,
        ],
        loader: 'babel-loader',
      }
    ]
  },
  node: {
    dns: 'empty',
    fs: 'empty',
    module: 'empty',
    net: 'empty',
    tls: 'empty',
  },
  target: 'web',
  mode: 'production',
};

As you can see, it's not all too different from the webpack test, but:

  • I need it to be built so it can be consumed by webpack yet again via angular's CLI and build process.
  • I need it to work with SSR, so "window" is a no-no. For example, the npm package "mongoose-browser" breaks SSR because of how it's presumably built.
  • Because of angular's purist approach with the CLI, just importing mongoose/browser doesn't work.

So in my case, webpack needs to do very little.

I have a feeling these goals might even be contradictory to what was in mind for this issue. Unless I'm missing something, I'm not sure how to make everyone happy without actually having at least two different mongoose-browser versions :-/. Or maybe my goals are just too specific for the scope of this issue.

Even so, there are some questions as to how it should be organized (where it should be output, testing, etc). I'd be happy to pitch in if you have some guidance for me.

@captaincaius
Copy link
Contributor

Since I never heard back about specifics, I decided to just throw together a PR - if any of the details need work I'll just address them thereafter ;).

@hasezoey
Copy link
Collaborator

should this issue be closed because #8350 is merged?

@vkarpov15 vkarpov15 removed this from the 6.x Unprioritized milestone Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience This issue improves error messages, debugging, or reporting
Projects
None yet
Development

No branches or pull requests

4 participants