zoukankan      html  css  js  c++  java
  • webpack2使用ch2-entry和output简要说明

    1 entry打包入口 打包字符串和数组

    const webpack = require('webpack'),
          path = require('path');
    
    module.exports = {
        entry: './src/script/main.js' //字符串
        //entry: ['./src/script/main.js', './src/script/a.js'], //数组
        output: {
            path: path.resolve(__dirname, './dist/js'),
            filename: 'hundle.js' //字符串或数组时输出为单个文件
        }
    };

    1.1 打包

    2 打包对象时 

    const webpack = require('webpack'),
          path = require('path');
    
    module.exports = {
        entry: {
          main: './src/script/main.js', //如果只有这个对象时
        },
        output: {
            path: path.resolve(__dirname, './dist/js'),
            filename: 'hundle.js' //可以指定一个固定的文件
        }
    };
    const webpack = require('webpack'),
          path = require('path');
    
    module.exports = {
        entry: { //打包多个对象时
          main: './src/script/main.js',
          a: './src/script/a.js'
        },
        output: {
            path: path.resolve(__dirname, './dist/js'),
            //必须分开输出
            filename: '[name]-[chunkhash].js' //命名格式 保证生成多个对象
        }
    };

    或者格式为

    filename: '[name]-[hash].js' //命名格式

     每次编译不管是否修改文件名都会变

  • 相关阅读:
    Vue数据双向绑定原理
    JS递归
    JS数据结构-链表
    JS数据结构-树
    React性能优化手段
    Django请求的生命周期
    Devops-git初识
    Django数据迁移的问题
    无监控,不运维!运维监控工具平台建设总结
    数据库-数据类型及主键外键
  • 原文地址:https://www.cnblogs.com/easyweb/p/6670726.html
Copyright © 2011-2022 走看看