Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.

using plugins.cn

e-cloud edited this page Mar 19, 2016 · 1 revision

Use plugins to add functionality typically related to bundles in webpack. For example, the BellOnBundlerErrorPlugin will notify you of an error in the bundler build process.

使用插件来添加通常涉及到webpack打包的功能。举个栗子,BellOnBundlerErrorPlugin这个插件会通知你打包构建过程出现的错误。

Built-in plugins

内置插件

Plugins are included in your module by using the plugins property in the webpack config.

插件是通过使用webpack配置中plugins属性来引入到你的模块。

// webpack should be in the node_modules directory, install if not.
var webpack = require("webpack");

module.exports = {
	plugins: [
		new webpack.ResolverPlugin([
			new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
		], ["normal", "loader"])
	]
};

Other plugins

其他插件

Plugins that are not built-in may be installed via npm if published there, or by other means if not:

未内置插件如果在NPM发布了可以通过NPM安装,或如果不是的话,以其他方式安装:

npm install component-webpack-plugin

which can then be used as follows:

然后可以如下使用:

var ComponentPlugin = require("component-webpack-plugin");
module.exports = {
	plugins: [
		new ComponentPlugin()
	]
}

When installing third party plugins via npm it is advised to use this tool: https://www.npmjs.com/package/webpack-load-plugins

当通过NPM安装第三方插件时,建议使用这个插件: webpack-load-plugins

It checks for all third party plugins installed in your dependencies and lazyloads them when you need them.

它会检测安装在你的依赖[感觉有点不妥]里的所有第三方插件,并在你需要使用它们的时候懒加载。

See also

同见

Clone this wiki locally