Skip to content

Commit

Permalink
feat: support extra less options in dev and build mode (umijs#112)
Browse files Browse the repository at this point in the history
* feat: support extra less options in dev and build mode

* fix: change config name, add e2e test case

* fix: remove docz cache
  • Loading branch information
focus7eleven authored and sorrycc committed Sep 26, 2019
1 parent acbff76 commit c91df2b
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ import $inject_window_foo from 'foo';
console.log($inject_window_foo);
```

#### lessInRollupMode

在 rollup 模式下做 less 编译,支持配置 less 在编译过程中的 Options

* Type: `Object`
* Default: `{}`

可以配置 modifyVars 等, 详见 less 的 [Options 文档](http://lesscss.org/usage/#less-options)

#### lessInBabelMode

在 babel 模式下做 less 编译,基于 [gulp-less](https://github.com/gulp-community/gulp-less),默认不开启。
Expand Down
2 changes: 2 additions & 0 deletions packages/father-build/src/getRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function(opts: IGetRollupConfigOpts): RollupOptions[] {
typescriptOpts,
nodeResolveOpts = {},
disableTypeCheck,
lessInRollupMode = {},
} = bundleOpts;
const entryExt = extname(entry);
const name = file || basename(entry, entryExt);
Expand Down Expand Up @@ -145,6 +146,7 @@ export default function(opts: IGetRollupConfigOpts): RollupOptions[] {
{
plugins: [new NpmImport({ prefix: '~' })],
javascriptEnabled: true,
...lessInRollupMode,
},
],
],
Expand Down
1 change: 1 addition & 0 deletions packages/father-build/src/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const successValidates = {
extraBabelPlugins: [[]],
extraBabelPresets: [[]],
extraPostCSSPlugins: [[]],
lessInRollupMode: [{}],
cssModules: [true, false, {}],
autoprefixer: [{}],
include: ['node_modules', /node_modules/],
Expand Down
3 changes: 3 additions & 0 deletions packages/father-build/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export default {
inject: {
type: 'object',
},
lessInRollupMode: {
type: 'object'
},
lessInBabelMode: {
oneOf: [
{ type: 'boolean' },
Expand Down
3 changes: 3 additions & 0 deletions packages/father-build/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export interface IBundleOptions {
nodeResolveOpts?: {
[value: string]: any;
};
lessInRollupMode?: {
[opt: string]: any
}
}

export interface IOpts {
Expand Down
12 changes: 12 additions & 0 deletions packages/father/src/doc/doc.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ beforeAll(async () => {
await doc('css-modules');
await doc('config-theme');
await doc('babel-extra-babel-presets-and-plugins');
await doc('less-options');
browser = await puppeteer.launch({ args: ['--no-sandbox'] });
});

Expand Down Expand Up @@ -119,6 +120,17 @@ test('babel-extra-babel-presets-and-plugins', async () => {
expect(title).toEqual('p1|p2|p1|p2|haha');
});

test('less-options', async () => {
await page.goto(`http://localhost:${servers['less-options'].port}/`, {
waitUntil: 'networkidle2',
});
const buttonColor = await page.evaluate(() => {
const el = document.querySelectorAll('button')[1]
return window.getComputedStyle(el).color
});
expect(buttonColor).toEqual('rgb(255, 0, 0)');
});

afterAll(() => {
Object.keys(servers).forEach(name => {
servers[name].server.close();
Expand Down
4 changes: 4 additions & 0 deletions packages/father/src/doc/doczrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default {
cssmodules: true,
loaderOpts: {
javascriptEnabled: true,
...userConfig.lessInRollupMode
},
}),
css({
Expand All @@ -125,6 +126,7 @@ export default {
cssmodules: false,
loaderOpts: {
javascriptEnabled: true,
...userConfig.lessInRollupMode
},
}),
]
Expand Down Expand Up @@ -154,6 +156,7 @@ export default {
cssmodules: false,
loaderOpts: {
javascriptEnabled: true,
...userConfig.lessInRollupMode
},
}),
css({
Expand All @@ -164,6 +167,7 @@ export default {
cssmodules: true,
loaderOpts: {
javascriptEnabled: true,
...userConfig.lessInRollupMode
},
}),
]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"vendors.js": "/static/js/vendors.9cfde6cc.js",
"app.js": "/static/js/app.48e8e6e0d1bea43fcc95.js",
"button-index.css": "/static/css/button-index.48e8e6e0d1bea43fcc95.css",
"button-index.js": "/static/js/button-index.984dc1e1.js",
"index.html": "/index.html"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="description" content="My awesome app using docz"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>My Doc</title><link rel="icon" type="image/x-icon" href="https://cdn-std.dprcdn.net/files/acc_649651/LUKiMl"><script src="https://gw.alipayobjects.com/os/lib/react/16.8.6/umd/react.production.min.js"></script><script src="https://gw.alipayobjects.com/os/lib/react-dom/16.8.6/umd/react-dom.production.min.js"></script></head><body><div id="root"></div><script src="/static/js/vendors.9cfde6cc.js"></script><script src="/static/js/app.48e8e6e0d1bea43fcc95.js"></script></body></html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.index_btn__2EqaA{color:red}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c91df2b

Please sign in to comment.