Javascript 在下划线模板网页包中使用下划线函数会引发未定义的错误
我正在尝试将我的项目设置为使用Gulp with Webpack作为绑定器,我使用下划线模板,其中一个模板中我使用了Javascript 在下划线模板网页包中使用下划线函数会引发未定义的错误,javascript,templates,gulp,underscore.js,webpack,Javascript,Templates,Gulp,Underscore.js,Webpack,我正在尝试将我的项目设置为使用Gulp with Webpack作为绑定器,我使用下划线模板,其中一个模板中我使用了\uUeach()。当我运行webpack然后重新加载时,我得到一个错误uncaughtreferenceerror:u未定义它指向模板,有人能告诉我如何向模板公开下划线吗 网页包配置 gulp.task('webpack', function() { return gulp.src('./app/scripts/index.js') .pipe(w
\uUeach()
。当我运行webpack然后重新加载时,我得到一个错误uncaughtreferenceerror:u未定义
它指向模板,有人能告诉我如何向模板公开下划线吗
网页包配置
gulp.task('webpack', function() {
return gulp.src('./app/scripts/index.js')
.pipe(webpack({
// watch: true,
devtool: 'source-map',
debug: true,
output: {
filename: 'bundle.js',
path: __dirname
},
module: {
loaders: [
{
test: /\.html$/,
loader: 'underscore-template-loader',
query: {
prependFilenameComment: __dirname,
},
exclude: /node_modules/,
},
{ test: /imagesloaded/, loader: 'imports?define=>false&this=>window'},
{ test: /underscore/, loader: 'exports?_' }
// { test: /backbone/, loader: 'exports?Backbone!imports?underscore,jquery' }
]
}
}))
.pipe(gulp.dest('./dist/scripts'));
});
模板
<% _.each(movies, function(movie) { %>
<a href="/movie/<%= movie.id %>" class="movie js-movie--show" data-id="<%= movie.id %>">
<img src="<%= movie.backdrop_small %>" alt="" class="trans-img is-hidden js-trans-img">
<span class="movie__info">
<h2><%= movie.title %></h2>
</span>
</a>
<% }); %>
我看到你在使用它,但我没有看到你包括它。你在哪里链接/
require()
underline.js
或underline.min.js
?我需要使用webpack.ProvidePlugin使下划线全局可用
gulp.task('scripts', function () {
var exchange = {
source_map: {
file: 'bundle.js.map',
root: '/',
orig: ''
}
};
var b = browserify({
entries: './app/scripts/index.js',
debug: true,
transform: ['jstify']
});
return b.bundle()
.pipe(plumber())
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(extractor({
removeSourcesContent: true
}))
.on('postextract', function(sourceMap) {
exchange.source_map.orig = sourceMap;
})
.pipe(filter('**/*.js'))
.pipe(gulp.dest('./dist/scripts/'));
});