我已經通過Webpack成功地將select2.js的本地副本與幾個* .js文件捆綁在一起。但是,它總是拋出一個TypeError,它警告e.select2不是函數。有趣的是,如果我需要CDN中的select2.js,它會在初始頁面加載時工作,但在刷新頁面後會引發相同的錯誤。select2與Webpack的TypeError
在做捆綁之前,這個錯誤從未發生過。
任何人都可以請建議?謝謝!
根據要求,我在下面分享webpack.config.js。
var path = require("path");
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
module.exports = {
context: __dirname,
entry: {
annotation: './assets/js/annotation_index',
subject: './assets/js/subject_index',
highchart: './assets/js/highchart_index',
protocol: './assets/js/protocol_index',
subscription: './assets/js/subscription_index'
},
output: {
path: path.resolve('./assets/bundles/'),
filename: "[name].js",
},
externals: [
require('webpack-require-http')
],
plugins: [
new BundleTracker({filename: './webpack-stats.json'})
],
module: {
loaders: [
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', query: {compact: false} }, // to transform JSX into JS
],
},
resolve: {
modulesDirectories: ['node_modules', './assets/js/annotation'],
extensions: ['', '.js', '.jsx'],
alias: { jquery: "./jquery"}
},
}
嘗試分享@JaganathanBantheswaran我剛剛共享webpack.config文件之上的webpack.config文件 – Thaadikkaaran
。請建議。謝謝! – Qiao