前端野蛮生长的时代已通过去了。随着前端的发展,愈来愈复杂的业务,各类各样的插件模块依赖关系,项目复杂度的提高,开发成本愈来愈高。webpack就是解决了这一系列的问题。你能够利用webpack管理各类资源,也能够提早享受es6语法的便利,也能够规范成员之间的开发规范,等等。
关于wepback配置说明,不少同窗都已经分享过不少了,此次分享一下能够直接使用一份webpack项目html
目前暂时不支持vue,react前端
yarn add jay-webpack-scaffold
cp ./node_modules/jay-webpack-scaffold/webpack/config.dist.js ./webpack-config.js
根据需求调整相应目录vue
entry: 须要编译输出的js 根路径 output: 输出的路径 mainJs: 全局使用的js文件路径 lessPath: 须要编译输出的less 根路径,该目录下,都会被编译输出 publicPath: 开发环境下,使用路径 author: 做者名称 removePattern: 不须要被输出的文件路径 正则表达式,例如 /^\/css\/.*\.js?$/,表示css目录下的全部js文件都不输出(当less做为入口文件时,会输出js文件) purifyCssPaths: 被使用到css的全部文件地址,如html页面和js,它会过滤除了这些被使用的css样式 copyLibs: 须要拷贝的类库,能够拷贝目录,也能够拷贝单独文件 alias: 引用别名,加快编译速度 libs: js类库目录,每一个文件都会单独输出,能够对已有的类库模块封装输出
./node_modules/.bin/eslint --init
修复js代码格式html5
./node_modules/.bin/eslint --fix filepath
规则列表:https://eslint.org/docs/rules/node
项目根目录 .stylelintrcreact
{ "extends": "stylelint-config-standard" }
忽略文件配置 .stylelintignore
规则列表:https://stylelint.io/user-gui...webpack
规范:git
"scripts": { "build": "NODE_ENV=production settingPath='/webpack-config.js' webpack --config '/node_modules/jay-webpack-scaffold/webpack/webpack.js'", "dev": "NODE_ENV=development settingPath='webpack-config.js' webpack-dev-server --config '/node_modules/jay-webpack-scaffold/webpack/webpack.js'", }
你也能够这样使用
webpack.config.jses6
const webpackConfig = require('jay-webpack-scaffold'); module.exports = webpackConfig; // 能够自主配置loadeer,plugin,及其余参数
package.json
"scripts": { "build": "NODE_ENV=production settingPath='/webpack-config.js' webpack --config 'webpack.config.js'", "dev": "NODE_ENV=development settingPath='webpack-config.js' webpack-dev-server --config 'webpack.config.js'", }
本地开发环境执行如下命令:
npm run dev
它将会文件生成好,放入内存中。自动监听文件变化
<br/>
生产环境执行如下命令:
npm run build
它将会生产静态资源文件到你定义的目录下
location ~ ^/dist { if (-f $root_dir/dev.lock){ proxy_pass http://127.0.0.1:8082; } }
任何/dist/* 的请求,都会代理到http://127.0.0.1:8082,根据不一样需求相应配置
lsof -i:8082 (查看占用端口进程) kill -9 PID (pid 为进程id号)