Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit 0b2c77b

Browse files
committed
Fixed require.context
1 parent ce88fa0 commit 0b2c77b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-docgen-api",
3-
"version": "2.0.10",
3+
"version": "2.0.11",
44
"description": "Toolbox to extract information from Vue component files for documentation generation purposes.",
55
"bugs": {
66
"url": "https://github.com/vue-styleguidist/vue-docgen-api/issues"

src/utils/getSandbox.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ function getMixins(code, file) {
4848
const evalComponentCode = (code) => {
4949
try {
5050
const script = new vm.Script(code, {});
51+
let requireSanbox = function(element){
52+
if (element === 'vuex') {
53+
return {
54+
mapState: function(){},
55+
mapMutations: function(){},
56+
mapGetters: function(){},
57+
mapActions: function(){}
58+
}
59+
}
60+
return function(){}
61+
}
62+
requireSanbox.context = function(){
63+
return function(){}
64+
}
5165
const sandbox = {
5266
exports: {},
5367
Vue: {
@@ -58,17 +72,7 @@ const evalComponentCode = (code) => {
5872
exports: {
5973
},
6074
},
61-
require:(element)=> {
62-
if (element === 'vuex') {
63-
return {
64-
mapState: function(){},
65-
mapMutations: function(){},
66-
mapGetters: function(){},
67-
mapActions: function(){}
68-
}
69-
}
70-
return function(){}
71-
},
75+
require:requireSanbox,
7276
document: {},
7377
window: {
7478
location: {},

tests/components/vuex/example.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
</template>
33
<script>
44
import {mapGetters} from 'vuex'
5+
const ctx = require.context('some/path', true, /.jpg$/);
6+
57
/**
68
* Partial mapping, object spread operator example
79
*/

0 commit comments

Comments
 (0)