简体   繁体   中英

Import npm module as source code

I want to import the source code for vue-form-generator to make some changes to the source code. Being new to Node and Javascript, I really have no idea what I'm doing. Can someone please guide me through the steps?

Since my Vue project is in Typescript, previously when I was using npm install vue-form-generator I'd created vfg.d.ts

declare module "vue-form-generator" {
  const VueFormGenerator: any;
  export default VueFormGenerator;
}

and my main.ts was

import VueFormGenerator from 'vue-form-generator';
Vue.component('VueFormGenerator', VueFormGenerator);

Now I have copied everything from their /src to my /src/component/form-generator but have no idea how to make it so I can use as previously.

If you are creating your own fork of vue-form-generator , you may add type declarations right there as well.

create file index.d.ts in your copy of src/component/form-generator :

  const VueFormGenerator: any;
  export default VueFormGenerator;

There is no need to have declare module ... in there because this index.d.ts is right next to index.js , so TypeScript compiler should find it when you import it as

import VueFormGenerator from './relative-path-to/form-generator/index';

and generated javascript code will find it as index.js there. Note that the import path must be relative because otherwise, without any path mapping, it will look for the module in node_modules , not in your sources.

You also have to remove all references to the previous type declaration file, vfg.d.ts , in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM