导入引导JavaScript,网页包
我试图从引导JS组件中仅导入折叠组件,如下所示:导入引导JavaScript,网页包,javascript,jquery,twitter-bootstrap,webpack,gulp,Javascript,Jquery,Twitter Bootstrap,Webpack,Gulp,我试图从引导JS组件中仅导入折叠组件,如下所示: import "../../../node_modules/bootstrap/js/dist/collapse"; 除了jQuery,一切都很好,这个文件(collapse.js)需要jQuery,它被编译到我的main.js文件中,如何避免呢?我已经包括了来自CDN的jQuery 这是我的大口/网页包配置 let webpackConfig = { module: { rules: [ { test:
import "../../../node_modules/bootstrap/js/dist/collapse";
除了jQuery,一切都很好,这个文件(collapse.js)需要jQuery,它被编译到我的main.js文件中,如何避免呢?我已经包括了来自CDN的jQuery
这是我的大口/网页包配置
let webpackConfig = {
module: {
rules: [
{
test: /.js$/,
use: [
{
loader: 'babel-loader'
}
]
}
]
}
};
// Combine JavaScript into one file
// In production, the file is minified
function javascript() {
return gulp.src(PATHS.entries)
.pipe(named())
.pipe($.sourcemaps.init())
.pipe(webpackStream(webpackConfig, webpack2))
.pipe($.if(PRODUCTION, $.uglify()
.on('error', e => { console.log(e); })
))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(PATHS.dist + '/assets/js'));
}
更新,解决方案:
let webpackConfig = {
externals: { jquery: 'jQuery' },
module: {
rules: [
{
test: /.js$/,
use: [
{
loader: 'babel-loader'
}
]
}
]
}
};
你可以使用Webpack来阻止它将一些包包含到你的包中。
尝试使用反应引导程序,这样你就可以只导入你需要的东西,而且它更容易,在这种情况下你只能使用WebPACK。我绝对不会在这一点上这样做的:我100%肯定有排除JQuery的方法,例如基金会DO。