Skip to content

Commit 692823b

Browse files
committed
refactor: load a webpack loader in a modular way
added webpack-bundle-analyzer by the way
1 parent 58d0f36 commit 692823b

17 files changed

+206
-89
lines changed

.storybook/webpack.config.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
const merge = require('webpack-merge');
1+
const tsLoader = require('../build/loaders/ts-loader');
2+
const sassLoader = require('../build/loaders/sass-loader');
23

3-
const webpackBaseConfig = require('../build/webpack.css');
4-
5-
module.exports = merge(webpackBaseConfig, {});
4+
module.exports = {
5+
module: {
6+
rules: [tsLoader, sassLoader],
7+
},
8+
};

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [x] 代码风格检测
2929
- [x] 单元测试
3030
- [x] commit message 提交规范
31+
- [x] 支持打包文件大小分析
3132

3233
## 规范
3334

@@ -154,4 +155,9 @@ module.exports = {
154155

155156
组件库本身有一套自己的 CSS 命名规则,保证唯一的命名空间以及可以方便的进行修改。所以 scoped 和 CSS Module 对于组件库来说是没有意义的。但是在 .vue 文件中使用 `<style></style>` 标签的话 `vue-loader` 一定会把相关的 CSS 处理逻辑(如模拟 scoped 特性)打包进最终的文件里。所以采用分离的方式编写 CSS,也能做到组件库样式的统一管理。
156157

157-
> 如果你有什么建议或者想法可以给我发邮件 rubykaikai@gmail.com 来一起探讨哦!~
158+
> 如果你有什么建议或者想法可以给我发邮件 rubykaikai@gmail.com 来一起探讨哦!~
159+
160+
## TODO
161+
162+
* webpack 插件自动上传图片
163+
* 修改使用文档,加入 CI/CD greenkeeper 的配置方法

bin/qiniu-deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const glob = require('glob');
33
const mime = require('mime-types');
44

5-
const upload = require('../build/qiniu');
5+
const upload = require('../build/utils/qiniu');
66

77
const dirPath = path.resolve(
88
__dirname,

build/loaders/babel-loader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
test: /\.js$/,
5+
loader: 'babel-loader',
6+
include: path.resolve(__dirname, '../components'),
7+
};

build/loaders/sass-loader.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2+
3+
const TARGET = process.env.npm_lifecycle_event;
4+
5+
module.exports = {
6+
test: /\.scss$/,
7+
use: [
8+
{
9+
loader:
10+
TARGET.indexOf('storybook') !== -1
11+
? 'vue-style-loader'
12+
: MiniCssExtractPlugin.loader,
13+
options: {
14+
esModule: true,
15+
},
16+
},
17+
{
18+
loader: 'css-loader',
19+
},
20+
'postcss-loader',
21+
{
22+
loader: 'sass-loader',
23+
options: {
24+
prependData: `$color: green;`,
25+
},
26+
},
27+
],
28+
};

build/loaders/ts-loader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
test: /\.ts$/,
3+
loader: 'ts-loader',
4+
options: { appendTsSuffixTo: [/\.vue$/] },
5+
};

build/loaders/url-loader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
test: /\.(png|jpe?g|gif)$/i,
3+
use: [
4+
{
5+
loader: 'url-loader',
6+
options: {
7+
limit: 1024,
8+
},
9+
},
10+
],
11+
};

build/loaders/vue-loader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
test: /\.vue$/,
3+
loader: 'vue-loader',
4+
};
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
const fs = require('fs');
2-
const path = require("path");
3-
4-
function resolve(filepath) {
5-
return path.resolve(__dirname, filepath);
6-
}
2+
const path = require('path');
73

84
function getEntries() {
9-
const dir = resolve("../components");
5+
const dir = path.resolve(__dirname, '../../components');
106
const packages = fs.readdirSync(dir);
117
const entries = {};
128
packages.forEach(function(pkg) {
139
const dirpath = path.join(dir, pkg);
1410
const stat = fs.statSync(dirpath);
1511
if (stat && stat.isDirectory()) {
16-
entries[pkg] = path.join(dirpath, "index.js");
12+
entries[pkg] = path.join(dirpath, 'index.js');
1713
}
1814
});
1915
return entries;
2016
}
2117

22-
exports.resolve = resolve;
2318
exports.getEntries = getEntries;
File renamed without changes.

0 commit comments

Comments
 (0)