Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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 如何使用webpack处理仅在运行时可用的服务器端依赖关系_Javascript_Pug_Bundle_Webpack_Require - Fatal编程技术网

Javascript 如何使用webpack处理仅在运行时可用的服务器端依赖关系

Javascript 如何使用webpack处理仅在运行时可用的服务器端依赖关系,javascript,pug,bundle,webpack,require,Javascript,Pug,Bundle,Webpack,Require,我们有一个文件需要在运行时在服务器端呈现jade模板 define(['underscore', 'html!/templates/myTemplate'], function (_, template){ ... }) 其思想是在编译时捆绑其他依赖项(此处下划线),但仅在运行时需要该模板 我们尝试使用这样的外部命令,但没有改变任何事情 externals: { '/templates/myTemplate': '/templates/myTemplate' } 但编译包时会

我们有一个文件需要在运行时在服务器端呈现jade模板

define(['underscore', 'html!/templates/myTemplate'], function (_, template){
    ...
})
其思想是在编译时捆绑其他依赖项(此处下划线),但仅在运行时需要该模板

我们尝试使用这样的外部命令,但没有改变任何事情

externals: {
    '/templates/myTemplate': '/templates/myTemplate'
}
但编译包时会显示相同的错误:

Module not found: Error: Cannot resolve 'file' or 'directory' /templates/myTemplate ...
有什么想法吗

这是我们的设置文件

module.exports = {
  context: __dirname,
  entry: {
    "pageA": "./pageA.js",
    "pageB": "./pageB.js"
  },

  output: {
    "path": __dirname + '/dist',
    "publicPath": './javascripts/dist/',
    "filename": '[name].js'
  },

  plugins: [
      new webpack.ProvidePlugin({
          $: "jquery",
          jQuery: "jquery"
      })
  ]
};

仅使用网页包是不可能的:

使用
require(['dependency'],回调(dependency){})如同一问题所示,如果我将模板放在原始define回调中的单独require中,webpack会在编译时尝试加载模板。