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

时间:2016-04-12 10:00:05

标签: javascript pug bundle webpack require

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

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"
      })
  ]
};

1 个答案:

答案 0 :(得分:0)

仅使用Webpack无法实现:https://github.com/webpack/webpack/issues/2326