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

Add Node.js esm entry point #1872

Merged
merged 5 commits into from
Nov 22, 2020
Merged

Conversation

sebamarynissen
Copy link

@sebamarynissen sebamarynissen commented Nov 13, 2020

This PR adds a Node.js esm entry point for Vuex. Currently it is already possible to do

import Vuex from 'vuex'

on Node 13.2 and up, but unfortunately it's not possible to do

import { mapGetters } from 'vuex';

because Node doesn't support named imports from CommonJS (note: it actually does, but only if the imported cjs file adheres to some rules, such as using exports.mapGetters). This PR adds support for named imports on Node as well.

While it is possible to directly use dist/vuex.esm.js, this PR does not use that file but chooses to use an esm wrapper file as to avoid the dual package hazard.

Why?

Node.js now fully supports esm so let's encourage the migration process by improving interoperability of the code we write. I've created this PR in the wake of writing vue-esm-loader which allows importing .vue single-file components on Node without a build step. I noticed that I was unable to test my Vue components because they were using

import { mapState } from 'vuex';

export default {
  computed: {
    ...mapState(['state']),
  },
};

and hence decided to add this functionality to Vuex.

Related: chaijs/chai#1340

Copy link
Member

@kiaking kiaking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot on the PR! I've tested this at my environment too and it's working. Nice one 👍

I left a comment on not referencing src folder. Please have a look 🙏

package.json Outdated Show resolved Hide resolved
@kiaking kiaking added build Related to the build system enhancement New feature or request labels Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to the build system enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants