2016-12-14 79 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"},

    希望能幫到你:)