插件1 => ConsoleLogOnBuildWebpackPlugin.js
function ConsoleLogOnBuildWebpackPlugin() {
console.log(" 咋办 我被调用了....... ");
}
ConsoleLogOnBuildWebpackPlugin.prototype.apply = function(compiler) {
compiler.plugin('run', function(compiler, callback) {
console.log("webpack 构建过程开始!!!");
callback();
});
};
// 对外提供暴露接口
module.exports=ConsoleLogOnBuildWebpackPlugin;
插件2 => ConsoleLogOnBuildWebpackPlugin2.js
function ConsoleLogOnBuildWebpackPlugin2() {
console.log(" 2===> 咋办 我被调用了....... ");
}
ConsoleLogOnBuildWebpackPlugin2.prototype.apply = function(compiler) {
compiler.plugin('run', function(compiler, callback) {
console.log("webpack2 构建过程开始!!!");
callback();
});
};
// 对外提供暴露接口
module.exports=ConsoleLogOnBuildWebpackPlugin2;
webpack.config.js 配置文件
// require 写法来自于 Node js
// ES6 (import ==== export )
const consoleLogOnBuildWebpackPlugin =require('./plugins/ConsoleLogOnBuildWebpackPlugin');
const consoleLogOnBuildWebpackPlugin2 =require('./plugins/ConsoleLogOnBuildWebpackPlugin2');
module.exports = {
entry: {
main:['../src/js/app.js','../src/js/app1.js']
},
output: {
filename: '[name].[hash:8].js',
chunkFilename: 'js/[chunkhash:8].js',
},
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
},
plugins: [
new consoleLogOnBuildWebpackPlugin(),
new consoleLogOnBuildWebpackPlugin2()
]
};
执行结果: