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

package.json points to dist/vue-moment.js which does not have conditional moment inclusion fix #117

Open
sagerb opened this issue May 1, 2019 · 2 comments

Comments

@sagerb
Copy link

sagerb commented May 1, 2019

Within an existing project which uses webpack, yarn and moment.js, I recently added vue-moment as a dependency. Using webpack's bundle analysis, I quickly saw that the size of vue-moment was as big as moment itself.

I believe this to be occurring because webpack auto-resolves the import of vue-moment by examing the file node_modules/vue-moment/package.json. This file contains an entry for "main" which points to the copy of vue-moment.js within the dist folder, which continues to have the moment code "inline" (and does not match up with the conditional inclusion present within the node_modules/vue-moment/vue-moment.js file.

{
  "name": "vue-moment",
  "version": "4.0.0",
  "description": "Handy Moment.js filters for your Vue.js project",
  "main": "dist/vue-moment.js",

While I can resolve this using a combination of:

  1. a specific alias within my webpack config:
  resolve: {
    alias: {
      'vue-moment': path.resolve(
        __dirname,
        'node_modules/vue-moment/vue-moment.js'
      ),
    },
  },
  1. de-duplicate my yarn.lock file (using a package called yarn-deduplicate)

I don't believe I should have to do this in order to minimize the footprint of vue-moment in my production bundle.

Have I discovered an issue or is this intentional by design?

@tryforceful
Copy link

I also have this issue, and believe this behavior should be fixed in vue-moment.

For me, setting the alias to to the ES module node_modules/vue-moment/dist/vue-moment.es.js allowed my configuration to import the moment code only once and keep the vue-moment slice small with only one step. (No need for deduplication.)

@BrockReece
Copy link
Collaborator

Yeah, this makes sense.
Is this what the 'module' field in the package.json should be used for?
If so, this should be an easy fix?

dpslwk added a commit to NottingHack/hms2 that referenced this issue Jun 4, 2020
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

3 participants