[英]What is the recommended way to include a global module with Webpack?
I'm working on a large application using Webpack that includes a global settings.js
file that all other modules need access to. 我正在使用Webpack开发一个大型应用程序,其中包括所有其他模块都需要访问的全局
settings.js
文件。 Rather than add an import settings from '../path/to/settings';
而不是
import settings from '../path/to/settings';
添加import settings from '../path/to/settings';
to the top of all modules, I'm hoping there is a more succinct way to make it available to all modules by default. 在所有模块的顶部,我希望有一种更简洁的方法,使其默认情况下可用于所有模块。
Suggestions for adding a module globally available to all others? 有关添加全局模块供其他所有人使用的建议?
Discovered I was already doing this with webpack.ProvidePlugin
. 发现我已经使用
webpack.ProvidePlugin
进行了此webpack.ProvidePlugin
。 Extended it to include my settings file: 扩展它以包括我的设置文件:
module.exports = {
resolve: {
modulesDirectories: [
'src',
'node_modules'
],
extensions: ['', '.json', '.js']
},
plugins: [
new webpack.ProvidePlugin({
settings: 'settings'
})
]
};
My settings.js
file is inside of src
, which is already being accesed via the resolve
Webpack config item. 我的
settings.js
文件位于src
内部,该文件已通过resolve
Webpack配置项进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.