Webpack required packaging problem

  node.js, question

项目结构

dist目录输出了2个?

I don’t understand why I requested lib.js. haven’t I packed it into home.min.js, and did I understand the code written by home.min.js without require lib.js wrong?

var webpack = require('webpack'),
 path = require('path'),
 CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
 
 var chunks = {
 "index": './src/js/index.js'
 };
 
 
 module.exports = {
 entry: chunks,
 output: {
 path: './dist/js/',
 filename: '[name].js'
 },
 module: {
 loaders: [
 bracket
 test: /\.js[x]?  $/,
 loaders: ['babel-loader?  presets[]=es2015'],
 exclude: /node_modules/,
 include: path.join(__dirname, '.')
 bracket
 bracket
 },
 // resolve: {
 //     alias: {
 //         js: path.join(__dirname,  "./src/js")
 //     },
 //     extensions: ['', '.js', '.json']
 // },
 plugins: [
 // new webpack.optimize.UglifyJsPlugin(),
 new CommonsChunkPlugin({
 name: "home.min",
 minChunks: 2,
 chunks: chunks
 }),
 bracket
 };
//index.js
 var Hello = require("./lib/lib.js");
 
 new Hello();
//lib.js
 var Hello = require("./lib/lib.js");
 
 new Hello();
new CommonsChunkPlugin({
 name: "home.min",
 minChunks: 2,
 chunks: chunks
 }),

Minchunks is set to 2, which means that at least two Chunk-referenced js modules will be placed in your home.min.js inside. Your lib.js has been referenced only once by index.js, so the contents of lib.js will be placed in the index.js inside generated after packaging.