Javascript 如何使用webpack处理仅在运行时可用的服务器端依赖关系
我们有一个文件需要在运行时在服务器端呈现jade模板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' } 但编译包时会
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会在编译时尝试加载模板。