如何使用 webpack 处理仅在运行时可用的服务器端依赖项
How to handle serverside dependency available only during runtime with webpack
我们有一个文件需要在运行时在服务器端呈现 jade 模板。
define(['underscore', 'html!/templates/myTemplate'], function (_, template){
...
})
想法是在编译时捆绑其他依赖项(此处下划线),但仅在运行时需要模板。
我们试过像这样使用外部设备,但没有任何改变。
externals: {
'/templates/myTemplate': '/templates/myTemplate'
}
但是编译bundle时报同样的错误:
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"
})
]
};
仅使用 Webpack 是不可能的:https://github.com/webpack/webpack/issues/2326
我们有一个文件需要在运行时在服务器端呈现 jade 模板。
define(['underscore', 'html!/templates/myTemplate'], function (_, template){
...
})
想法是在编译时捆绑其他依赖项(此处下划线),但仅在运行时需要模板。
我们试过像这样使用外部设备,但没有任何改变。
externals: {
'/templates/myTemplate': '/templates/myTemplate'
}
但是编译bundle时报同样的错误:
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"
})
]
};
仅使用 Webpack 是不可能的:https://github.com/webpack/webpack/issues/2326