brockpetrie / vue-moment

Handy Moment.js filters for your Vue.js project.
MIT License
1.31k stars 121 forks source link

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

Open sagerb opened 5 years ago

sagerb commented 5 years ago

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'
      ),
    },
    },
  2. 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 commented 4 years ago

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 commented 4 years ago

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?