简体   繁体   中英

import external js file in meteor project

I have a meteor project where I want to include the conversational form framework .

There is a npm package, however it is not properly imported (probably due to some kind of bug ). According to the github issue, this:

import cf from 'conversational-form'

does not work, because the export function exports cf.ConversationalForm , not cf (but cf is needed for existing declarations). The form is created and styled, but cannot be addressed in the js.

I was already able to use the framework in a normal html/js/css project, so now I wanted to just include the external script as a workaround. However, downloading + importing in client/main.js did not work for me.

I've tried:

import '/imports/api/conversational-form.min.js

as well as:

$.getScript

in Meteor.startup.

Do I need to write specific exports in the external .js? I'm far from a professional, so I'm a little hesitant to dissect the external .js.

Any tips on how to simply mimic the html-script-inclusion? Or other ideas on how to get the framework running?

Sincerely, desperate.

Well Meteor allows you many ways to do that, the first ideas that come to my mind are:

  1. Depending on your project structure you can create your own meteor package as a wrapper and internally load the library.
  2. Hardcoding the script tag in you entry point.(Im not sure if this would work to be honest but you can try).

I ended up downloading the script, modifying it to set my options and including it via \\imports .

VERY hacky solution, but well, it works...

Meteor allow you to load external library and scope them in all the client via the /compatibility folder.

Just put the file in there, and it will be scoped automaticaly.

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