最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Import non-module vendor script in webpack - Stack Overflow

programmeradmin2浏览0评论

I'm building an app with the AirConsole JS service. AirConsole only provides their library as a .js file you would include in your page with the usual:

<script type="text/javascript" src=".6.0.js"></script>

However, I'm using Webpack and would like to import the script into my other JS files. I have tried a few methods with no luck:

  1. Create an entry file named vendor which imports the airconsole.js file. This creates a vendor.bundle.js file which I can include on my page
  2. Add the AirConsole path to my index entry point so the script is included in the bundle.js file. With this method I can verify the AirConsole code is included in the bundle.js file but attempting to create a new instance of AirConsole results in AirConsole is undefined

Am I on the right track with these methods? If not, what is the remended way to import a non-module .js file?

I'm building an app with the AirConsole JS service. AirConsole only provides their library as a .js file you would include in your page with the usual:

<script type="text/javascript" src="https://www.airconsole./api/airconsole-1.6.0.js"></script>

However, I'm using Webpack and would like to import the script into my other JS files. I have tried a few methods with no luck:

  1. Create an entry file named vendor which imports the airconsole.js file. This creates a vendor.bundle.js file which I can include on my page
  2. Add the AirConsole path to my index entry point so the script is included in the bundle.js file. With this method I can verify the AirConsole code is included in the bundle.js file but attempting to create a new instance of AirConsole results in AirConsole is undefined

Am I on the right track with these methods? If not, what is the remended way to import a non-module .js file?

Share Improve this question asked Feb 3, 2017 at 22:56 Brett DeWoodyBrett DeWoody 62.9k31 gold badges144 silver badges192 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

The best way is by an action which we call "shimming". You can check out our new docs page for information. There are a few different ways to do on it (that depend on the needs) for your non-module.

https://webpack.js/guides/shimming/

发布评论

评论列表(0)

  1. 暂无评论