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

Add Node.js esm entry point #1872

merged 5 commits into from Nov 22, 2020

Conversation

@sebamarynissen
Copy link
Contributor

@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

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
sebamarynissen and others added 2 commits Nov 20, 2020
@kiaking kiaking merged commit acddab2 into vuejs:dev Nov 22, 2020
6 checks passed
6 checks passed
ci/circleci: install Your tests passed on CircleCI!
Details
ci/circleci: lint-types Your tests passed on CircleCI!
Details
ci/circleci: test-e2e Your tests passed on CircleCI!
Details
ci/circleci: test-ssr Your tests passed on CircleCI!
Details
ci/circleci: test-unit Your tests passed on CircleCI!
Details
deploy/netlify Deploy preview ready!
Details
@sebamarynissen sebamarynissen deleted the sebamarynissen:feature/node-esm branch Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants