2016-12-14 44 views
0

经过几个小时试图解决我的问题,我来到这里得到一些帮助。Bootstrap-sass jquery error

我想通过webpack和gulp加载Bootstrap javascript到我的项目,但我收到以下浏览器错误。

error message

这里是我的webpack.config的样子:

module.exports = { 
    output: { 
     filename: "bundle.js", 
    }, 
    resolve: { 
     // Add `.ts` and `.tsx` as a resolvable extension. 
     extensions: [ 
      "", 
      ".webpack.js", 
      ".web.js", 
      ".ts", 
      ".tsx", 
      ".js", 
      ".scss" 
     ] 
    }, 
    module: { 
     loaders: [ 
      { // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader` 
       test: /\.tsx?$/, 
       loader: "ts-loader" 
      } 
     ] 
    } 

}; 

它完全加载jQuery的,因为我可以使用它,但它似乎引导,青菜不会看到它。

下面是我的script.ts样子:

import * as $ from "jquery"; 
let bootstrap = require("../../node_modules/bootstrap-sass/assets/javascripts/bootstrap.min.js"); 

而且最后这里是我的gulpfile.ts:我

gulp.task("ts",() => { 
    gulp.src(["public/scripts/*.ts"]). 
     pipe(webpack(require("./webpack.config.ts"))). 
     pipe(uglify()). 
     pipe(gulp.dest("public/scripts")); 
}); 

感到非常沮丧,这是不行的。 我知道我可以使用bootstrap-sass-loader,但我更愿意通过gulp编译我的sass文件。

回答

1

Yohuuuu,我终于找到了答案。为了让自举-SASS知道的jquery我不得不通过NPM从这个loader.

  1. 安装装载机导入的jquery:

npm install imports-loader

  • 然后将此行添加到您的webpack.config.js中:
  • {test: /bootstrap-sass\/assets\/javascripts\//, loader: "imports?jQuery=jquery"},

    希望能帮到你:)