rollup-plugin-require-context icon indicating copy to clipboard operation
rollup-plugin-require-context copied to clipboard

rollup-plugin-require-context not working properly in Windows system compile environment

Open shenyi-dra opened this issue 3 years ago • 0 comments

Hi elcarim, i have facing the below issue for my current usage in Windows System.

Based on the different path seperator, in mac or linux system, the sepatator is '/', but in Windows Systme, the path.sep is '\'.

In resolve-require-code.js, the genRequireCode will trying to generate the import strings normal the require.context('packages/', true, /.vue$/) works on below folder structure. eg. pacakges/alert/src/index.vue packages/button/src/index.vue

but in windows system case. it will become packages\alert\src\index.vue pacakges\button\src\index.vue

and after the genRequireCode executed, the import string moduleProps will become below, './alert\src\index.vue': require_context_module_0_0, './button\src\index.vue': require_context_module_0_1'

And the keys methods the extract the keys from the import modules will trying to convert the string and get rid of the '\' in Windows System.

req.keys = function() {
   return Object.keys(map);
};

And at the end when i using the const files = require.context('packages/', true, /.vue$/) files.keys().forEach(key => { console.log(key); // each key become ./alertsrcindex.vue, all the windows separator is get rid of by the Object.keys method. })

shenyi-dra avatar Apr 01 '21 01:04 shenyi-dra