webpack& jQuery:不能很好地在一起玩

时间:2016-03-08 22:12:01

标签: jquery angularjs twitter-bootstrap typescript webpack

我正在尝试在我使用webpack开发的Angular 2应用程序中使用bootstrap的轮播组件。我遇到了需要bootsrap.js和jQuery.js的真正问题。

在stackoverflow和全球互联网上的其他地方有很多关于此主题的帖子。例如,This post看起来非常有希望,但我跟着它写了这封信,仍然在浏览器中收到错误:

SET SESSION AUTHORIZATION flasktut;
CREATE DATABASE some_db; -- somedb is owned by flasktut
RESET SESSION AUTHORIZATION;

在我的组件定义文件中,我有两个相当臭和怀疑的要求:

Uncaught Error: Bootstrap's JavaScript requires jQuery

我尝试了非缩小版本的bootstrap,.js以及需求的几个变体,例如require("../../../../node_modules/jquery/dist/jquery.js"); require('../../../../node_modules/bootstrap-sass/assets/javascripts/bootstrap.min.js'); ,但错误仍然存​​在。

请帮忙!我已经开始研究另一个项目,并且无法理解为什么jQuery不能正常播放。

我想做的一件事就是直接在组件中直接使用jQuery库,如下所示:

require('jquery')

可预见地,TypeScript编译器抱怨道。创建包含window.jquery = window.$ = require('jquery'); $成员的窗口界面无效。尽管如此,编译器还是抱怨道。

我现在对这个解决方案感到满意,直到找到一个不那么臭的解决方案。

对虚拟甜甜圈非常赞赏和奖励的想法或解决方案。

嗯。根据巴拉查德的建议,我尝试了以下方法:

jquery

这在VSC和webpack中产生了错误:import $ = require('jquery'); import bootstrap = require('bootstrap-sass'); cannot find module jquery。奇怪的是,删除分配,如下所示:

cannot find module bootstrap-sass

......并且神奇地找到了模块。关于嘶嘶声有不同的错误,但至少它找到了模块。

思想?

1 个答案:

答案 0 :(得分:0)

  

我有两个相当臭和怀疑看起来要求

应该是:

<div ng-repeat='json in myJson'>
   <p>{{json.id}}</p>
   <p>{{json.date}}</p>
   <div ng-repeat='item in json.nikola'>
      <p>{{item.title}}</p>
   </div>
</div>`

还有别的错。我可以向你保证string First; string Last; First = "Cristiano"; Last = " Ronaldo"; Console.Write("Please enter student name <First Last>: "); Console.WriteLine(First + Last); Console.WriteLine(" "); Console.WriteLine("*************NOTE**********************************************"); Console.WriteLine("*** Be sure to include decimal point for scores. ***"); Console.WriteLine("*** !!!All score should range from 0.00 to 100.00 !! ***"); Console.WriteLine("*** ***"); Console.WriteLine("*** For example : 80.50 ***"); Console.WriteLine("***************************************************************"); Console.WriteLine(" "); double Exam_1 = -1; double Exam_2; double Exam_3; double Assignment_1; double Assignment_2; Console.Write("Please enter score for Exam 1 <Example: 100.0>: "); Exam_1 = Convert.ToDouble(Console.ReadLine()); var exitProgram = false; var errorCount = 0; while (Exam_1 < 0.0 || Exam_1 > 100.0) { Console.Write("Exam score cannot be less than 0. or greater than 100.0. Please re-enter the score for Exam 1 <Example: 95.0>:"); Exam_1 = Convert.ToDouble(Console.ReadLine()); ++errorCount; ErrorCount(errorCount); } Console.Write("Please enter score for Exam 2 <Example: 0.0>: "); Exam_2 = Convert.ToDouble(Console.ReadLine()); errorCount = 0; while (Exam_2 < 0.0 || Exam_2 > 100.0) { Console.Write("Exam score cannot be less than 0.0 or greater than 100.0. Please re-enter the score for Exam 2 <Example: 95.0>:"); Exam_2 = Convert.ToDouble(Console.ReadLine()); ++errorCount; ErrorCount(errorCount); } Console.Write("Please enter score for Exam 3 <Example: 60.8>: "); Exam_3 = Convert.ToDouble(Console.ReadLine()); errorCount = 0; while (Exam_3 < 0.0 || Exam_3 > 100.0) { Console.Write("Exam score cannot be less than 0.0 or greater than 100.0. Please re-enter the score for Exam 3 <Example: 95.0>:"); Exam_3 = Convert.ToDouble(Console.ReadLine()); ++errorCount; ErrorCount(errorCount); } Console.WriteLine(" "); Console.Write("Please enter score for Assignment 1 <Example: 100.0>: "); Assignment_1 = Convert.ToDouble(Console.ReadLine()); errorCount = 0; while (Assignment_1 < 0.0 || Exam_2 > 100.0) { Console.Write("Assignment score cannot be less than 0.0 or greater than 100.0. Please re-enter the score for Assignment 1 <Example: 95.0>:"); Assignment_1 = Convert.ToDouble(Console.ReadLine()); ++errorCount; ErrorCount(errorCount); } Console.Write("Please enter score for Assignment 2 <Example: 23.46>: "); Assignment_2 = Convert.ToDouble(Console.ReadLine()); errorCount = 0; while (Assignment_2 < 0.0 || Assignment_2 > 100.0) { Console.Write("Assignment score can not be less than 0.0 or greater than 100.0. Please re-enter the score for Assignment 2 <Example: 56.0>: "); Assignment_2 = Convert.ToDouble(Console.ReadLine()); ++errorCount; ErrorCount(errorCount); } Console.WriteLine(" "); Console.WriteLine(" -------------- OUTPUT ---------------"); Console.WriteLine(" "); Console.Write("Student: "); Console.WriteLine(First + Last); Console.WriteLine(" "); Console.Write("Press any key to continue . . . "); Console.ReadLine(); } } public static void ErrorCount(int errorCount) { if (errorCount > 0) { Console.WriteLine("***** Invalid input entered. PROGRAN WILL END. PLease consult the user manual and restart the prrogram. ***** "); Console.WriteLine(" "); Console.Write("Press any key to exit . . . "); Console.ReadKey(); Environment.Exit(0); 只是有效。问题出在import $ = require('jquery'); // 1 import bootstrap = require('bootstrap'); // 2 及其npm包中。如果按此顺序进行这些导入,那么也应该可以正常工作。使用1进行编译。