我有2个入口点:一个是主应用程序,一个是应用程序的遗留部分。
legacy.js被捆绑在一起,就像我想要的那样:
module.exports = {
entry: {
app: ['file1', 'file2'],
legacy: ['legacyfile1', 'legacyfile2'],
},
devtool: 'source-map',
context: path.resolve(__dirname, 'src'),
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: 'js/[name].js'
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
chunks: ['app'] // Only include app bundle - Legacy will be required in the legacy javascript file.js at runtime.
}),
}
这将生成两个捆绑包,并且只有app.js捆绑包会注入到index.html中。
然后在legacy.js中,我想在文件顶部要求使用旧版捆绑包,类似这样的方法(全部不起作用,Webpack找不到模块):
require('./dist/js/legacy.js');
require('./js/legacy.js');
require('dist/js/legacy.js');
require('/js/legacy.js');
Webpack如何在运行时将Webpack捆绑文件转换为javascript文件?
感谢那些有时间考虑这一点的人!
答案 0 :(得分:0)
Webpack将每个入口点捆绑到一个普通脚本文件中,该脚本文件不会导出任何内容。因此,您无法CGImage
或$themes: (
default: (
theme: blue,
)
);
@function fetchColor($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
.navbar-brand {
background: fetchColor($themes, default, theme);
}
。
一种解决方案(不是通过全局范围共享代码)是找到两个捆绑软件的通用共享代码,并将其提取到单独的模块中,以便您可以从任一代码库中导入它。