Giter Club home page Giter Club logo

webpack-cli's Introduction

webpack-cli


自定义webpack开发设置,调整所需的开发环境(Vue,React,Ts等)

Getting Started


  • 安装依赖
npm install

Options


编辑根目录下web.config.js

module.exports = {
	...
}
Name Type Default Description
entry {String} '' 入口文件
outputPath {String} /dist 出口目录
title {String} 'webpack-cli' html文件标题(不使用自定义html模板时)
rootID {String} 'app' div标签的ID(不使用自定义html模板时)
extensions {Array} ['.js', '.css', 'json', '.less'] 引用文件可省略的后缀,必须包含.js
lazyLoading {Boolean} false 懒加载
alias {Object} {'@/': '/src'} 路径别名
html {String} '' 自定义html模板路径
multiPages {Object} '' 多页多入口文件
splitCode {Boolean} false 是否需要分割代码, 默认打包为一个文件
vue {Boolean} false 是否使用vue
react {Boolean} false 是否使用react
typescript {Boolean} false 是否使用typescript
  • server {Object}

webpack-dev-server的设置

server: {
	port: '8080',
	host: '0.0.0.0',
	proxy: {

	},
	index: 'index.html',
	https: false/true,
	openPage: ''
}
  • globalLib {Object}

不以import等模块化方式引入,需要以script或者link标签插入的文件
如果在多页环境下需指明chunks: {Array},即需要引入的页面

globalLib: {
	open: false/true,
	source: {string} 文件目录路径, 
	targetDir: {string} 打包后文件目录名, 
    externals: { object } `webpack`中externals配置
}

// E.g

globalConfig: {
	open: true,
	source: 'src/lib/config.js', 
	targetDir: 'lib', 
    externals: {
            
        }
}
  • multiPages

多页面,多入口设置
设置了multipages则不可用在设置单独设置entry

	multiPages: {
		index: {
			entry: {String} 入口文件},
			// 不需要引入的模块
			excludeChunks: ['login']
			// html: 如果使用自定义模板模板路径
		},

		// 入口名
		login: {

		}
	}
  • less

Less相关配置

	less: {
		// 引入less-plugin-functions
		lessFunction: false/true, 
		// common less file 公共less文件,不用引入即可使用
		// 不需要时设置为false
		lessCommon: {String} 
	}

使用Reacttypescript进行多页开发的web.config.js配置


module.exports = {
	multiPages: {
		index: {
			entry: 'src/index.tsx',
			excludeChunks: ['login']
		},
		login: {
			entry: 'src/login.tsx',
			excludeChunks: ['index']
		}
	},
	rootID: 'root',
	extensions: ['.js', '.ts', '.tsx', '.less'],
	libs: ['react', 'react-dom'],
	react: true,
	typescript: true,
	server: {
		port: '3333',
		index: 'login.html',
		openPage: 'index.html'
	}
}

Features


  • 支持单页面&多页面
  • 支持以<script>插入assets/config文件下所有js到指定html
  • devServer配置
  • 支持less,自定义函数,全局less
  • 支持vue,结合TypeScript(需要在src目录下新建vue-shims.d.ts)
  • 支持TypeScript开发
  • 支持自定义分割框架代码
  • 支持文件复制
  • 支持图片压缩以及转为base64
  • 支持react
  • eslint

webpack-cli's People

Contributors

homary avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.