Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在下划线模板网页包中使用下划线函数会引发未定义的错误_Javascript_Templates_Gulp_Underscore.js_Webpack - Fatal编程技术网

Javascript 在下划线模板网页包中使用下划线函数会引发未定义的错误

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

我正在尝试将我的项目设置为使用Gulp with Webpack作为绑定器,我使用下划线模板,其中一个模板中我使用了
\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/'));
});