Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dengwb1991/polymorphism-loader
A polymorphism loader
https://github.com/dengwb1991/polymorphism-loader
Last synced: about 22 hours ago
JSON representation
A polymorphism loader
- Host: GitHub
- URL: https://github.com/dengwb1991/polymorphism-loader
- Owner: dengwb1991
- Created: 2022-04-08T10:57:26.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-09T07:49:10.000Z (almost 3 years ago)
- Last Synced: 2024-12-17T02:29:36.338Z (24 days ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Polymorphism-loader
实现以文件维度条件编译
## 配置
```js
// webpack.config.jsrules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'polymorphism-loader',
options: {
mode: 'prod'
}
}]
}
]
``````js
// index.js
import bridge from './mode/bridge.js'// 目录结构如下
├── mode
│ ├── bridge.js
│ ├── bridge.dev.js
│ └── bridge.prod.js
├── index.js
```根据 `options.mode` 配置,匹配对应的文件.
若是开发环境(dev)下,则引入mode文件夹内的 `bridge.dev.js` 文件;
若是生产环境(prod)下,则引入mode文件夹内的 `bridge.prod.js` 文件;
若是其他环境下,则引入mode文件夹内的 `bridge.js` 文件;