
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
fe-common-build
Advanced tools
前端工程化之通用构建方案
前端的构建工具常用的大家都知道, 可能也在项目中运用过. 但大多是来一个项目写一份构建脚本, 没有提取出公共的构建能力. 而每个项目都复制一份新的构建脚本, 也不便于构建脚本的维护.
因此通用构建方案首先应该具备
而针对构建方案的具体功能, 无非就是处理前端的静态资源, 特别是 CSS/JS 以及图片类资源文件, 因此通用构建方案的能力就是
再着手实现构建方案的具体功能, 我们选用成熟的技术方案
再通过 gulp 做成一个个独立的构建任务, 将这些流程串起来. 通过可配置的参数, 来达到定制化的需求, 并实现资源的监听, 自动完成构建, 降低使用成本.
最后将构建方案发布为一个 npm 模块, 达成统一维护便于使用的目标.
安装 Node.js 6.x
将 example 目录中的文件复制一份到你的项目中
resources 目录下的示例文件可以不复制, 但需要保留这个目录用于放置前端的静态资源源码在你的项目目录下 npm install 安装依赖
构建是基于 gulp 的, 因此如果你没有安装 gulp command, 还需要 npm install gulp-cli -g
开发时使用 npm run dev 执行开发构建
开发完成时 npm run build 执行正式构建
正式上线时 npm run deploy 部署(FTP 上传)静态资源
| 命令 | 作用 | 说明 |
|---|---|---|
| npm run dev | 开发构建 | 会开启监听, 执行开发环境的构建 |
| npm run build | 正式构建 | 会先清理构建的结果, 再执行正式环境的构建 |
| npm run build:css | 构建 CSS | 支持参数:
|
| npm run build:js | 构建 JS | 支持的参数同 build:css |
| npm run build:res | 构建其他静态资源 | 支持的参数同 build:css |
| npm run clean | 清理构建的结果 | |
| npm run deploy | 部署(FTP 上传)静态资源 | 支持参数:
|
构建环境的差别, 默认为正式环境
dist 目录的 scss/less/js 文件就以 _ (下划线)开头__(两个下划线)开头, 会原封不动的复制一份到 dist 目录_ (下划线) 开头的 js 文件视为入口, 进行打包
_ (下划线) 开头的 scss/less 文件进行打包
如果项目在使用该构建方案时需要覆盖默认配置, 或者新增一些配置, 只需要在项目目录下新建一个 build-config.js, 参考 example/build-config.js
babel-preset-es2015 会给每个模块添加 "use strict"; 启用 ECMAScript 5 Strict Mode(ES5严格模式)
因此注意不要写违法严格模式的代码, 例如不使用 var 来声明变量, 让该变量被提升为一个全局变量. 启用严格模式可以让我们写出更规范的代码.
如果新增了需要打包的 js 文件, 需要重启构建任务
例如: 新增了一个 foo.js, 构建任务不会识别到这个新增的入口文件, 必须重启构建任务
FAQs
The npm package fe-common-build receives a total of 28 weekly downloads. As such, fe-common-build popularity was classified as not popular.
We found that fe-common-build demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.