简体   繁体   中英

gulp, browser-sync: external javascript files doens't executed

I want to give the extension "browser-sync" a chance but I do not get it to run. Maybe someone can give me a hint, what is wrong with my config / installation.

At first, the browser reload works like expected, but javascript code inside external .js files does not fire or throw an error or something else.

I used the settings from the gulpjs recipes located at: https://github.com/gulpjs/gulp/blob/master/docs/recipes/server-with-livereload-and-css-injection.md . so my filestructure and gulpfile are identical.

My gulpfile looks like:

var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;

gulp.task('serve', function() {
    browserSync({
        server: {
            baseDir: 'app'
        }
    });

    gulp.watch(['*.html', 'styles/**/*.css', 'scripts/**/*.js'], {cwd: 'app'}, reload);
});

and my index.html is:

<!DOCTYPE html>
<html lang="en">
<head>
    [...]
</head>
<body>
    <h1>Test</h1>

<script> console.log("foo") </script>

<!-- NOT WORKING-->
<script src="scripts/notworking.js" type="javascript"></script>

<script> console.log("bar") </script>
</body>
</html>

my notworking.js contains only the following 2 lines:

console.log("working?")
alert("working!");

but nothing happens. Only the "foo" and "bar" from the index.html file is displayed.

again, reload after filechanges works perfect, but the js code in my notworking.js file is not executed.

Does someone has an idea? Thanks in advance

<!-- NOT WORKING-->
<script src="scripts/notworking.js" type="javascript"></script>

type="javascript" is no valid mime-type

use type="text/javascript"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM