Recompile after imported file changed in meteor app

给你一囗甜甜゛ 提交于 2019-12-25 03:14:23

问题


I'm creating babel plugin to manage import paths according to some conditions based on file existence. On initial build everything works fine, but when I add or remove file that would impact result of the conditions, compiler doesn't recompile file that is importing changed file, therefore conditions are still resolved as if referenced file existed, but compiler is not able to find it.

I believe this is due to cache. So how can I manage/clear cache? Of course I would like to keep as much cacheing as possible. So, maybe, is there way to programmatically remove from cache only files that were impacted by my plugin?

Basically logic of plugin is as follows:

const fs = require("fs");
const fs_path = require("path");

function shouldResoulveImport(node) {
        /* some checks, returns bool */
}


module.exports = function(babel) {
    return {
       visitor: {
          ImportDeclaration(path, state) {
            if (!shouldResoulveImport(path.node)) {
              return;
            }

            const existing_file = /* some checking for another file existence */;

            if (existing_file) {
              path.node.source.value = existing_file;
            }
         }
       }
    };
 };

What i try to achieve is to use some default file for import, but when same file in other particular directory exists then change the import for the other file.

I use meteor 1.7 with babel 7 beta and react.

I've checked with babel support and it seems to be issue of meteor.

Thanks.


回答1:


There was no way to achieving it in this manner. So I decided to use try on import overriding file and exporting it further. And if the import fails, it means, that file doesn't exists so default file export its default content:

...
let toExport;
try {
    import Overrides from "overriding_path";
    toExport = Overrides;
} catch (e) {
    toExport = OriginalExport;
}

export default toExport;

Later just build plugin that instead of modifying import modifies file.



来源:https://stackoverflow.com/questions/51936972/recompile-after-imported-file-changed-in-meteor-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!