Javascript 在index.jade中包含脚本

Javascript 在index.jade中包含脚本,javascript,reactjs,pug,video.js,Javascript,Reactjs,Pug,Video.js,我想在index.jade文件中包含js文件的脚本。目前我添加了它们,但似乎并没有反映在UI上。我添加了markers.js脚本,该脚本本地存储在我的目录中。这是我的项目结构 这是我的index.jade文件的头脚本部分 block head_scripts script(src="https://code.jquery.com/jquery-2.0.3.min.js") script(src='https://vjs.zencdn.net/5.3.0/video.js')

我想在index.jade文件中包含js文件的脚本。目前我添加了它们,但似乎并没有反映在UI上。我添加了markers.js脚本,该脚本本地存储在我的目录中。这是我的项目结构

这是我的index.jade文件的头脚本部分

block head_scripts
    script(src="https://code.jquery.com/jquery-2.0.3.min.js")
    script(src='https://vjs.zencdn.net/5.3.0/video.js')
    link(href="https://vjs.zencdn.net/5.3.0/video-js.css" rel="stylesheet")
    script(src='https://vjs.zencdn.net/ie8/1.1.0/videojs-ie8.min.js')
    script(src='../client/pages/VideoScreen/markers.js')
    link(href='../client/pages/VideoScreen/marker.css' rel="stylesheet")
这是我的服务器文件

var debug  = require('debug')('tessact:node');
var app = express();


const IS_PROD = (process.env.NODE_ENV === "production");
const PORT = (process.env.PORT || 4200);

var routes = require('./routes').default;

if (app.get('env') === 'development') {
  app.locals.pretty = true;
}
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.set('env', IS_PROD ? 'production' : 'development');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(compression());
app.use('/public', express.static(
  path.resolve(__dirname, './public')
));

app.use('/', routes());
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers


// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}


// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});

const runServer = (app)=> {
  app.listen(PORT, ()=> {
    debug(`Listening on http://localhost:${PORT}`); 
    if (__DEV__)
      debug(`HMR on http://localhost:${config.BS_PORT}`);
  });  
}


runServer(app);

module.exports = 
应用程序


我添加的路径是否正确?我包括了脚本,但是标记根本没有出现。这意味着代码没有使用markers.js脚本。有人能给我一个解决方案吗?

应该从浏览器的角度给出路径,作为加载页面时请求的URL路径。因此,答案取决于您的服务器如何配置为提供客户机文件,如
marker.js
marker.css
,而不是您的项目结构。请查看更新@jonathanlonowskit。服务器似乎对
marker.
文件所在的
客户机
目录一无所知。但是
express.static()
中间件知道
public
目录。项目是否使用任何构建工具将文件从
client
复制(可能合并或压缩)到
public
?我确实在public文件夹中移动了markers.js。然后我更改了src='/markers.js'。这不管用。这有什么问题吗?中间件设置为以
/public
开头的路径(通过
app.use()
)的第一个参数),因此请尝试
src=“/public/marker.js”