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' //命名格式

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

  • 相关阅读:
    HTML 5 全局属性
    微软build 2015
    写个程序登陆58同城
    工厂方法
    简单工厂
    System.Data.SQLite兼容32位和64位问题
    利用Socket实现的两个程序的通信
    最近的工作总结
    Canvas路径、描边、填充
    HTML5阴影与渐变
  • 原文地址:https://www.cnblogs.com/easyweb/p/6670726.html
Copyright © 2011-2022 走看看