Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support config singular in .umirc.js #280

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/umi-build-dev/src/FilesGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class FilesGenerator {
this.service = service;
this.routesContent = null;
this.hasRebuildError = false;
this.layoutDirectoryName = service.config.singular ? 'layout' : 'layouts';
}

generate(opts = {}) {
Expand Down Expand Up @@ -60,7 +61,9 @@ export default class FilesGenerator {
initialValue: [
paths.absPagesPath,
join(paths.absSrcPath, '_routes.json'),
...EXT_LIST.map(ext => join(paths.absSrcPath, `layouts/index${ext}`)),
...EXT_LIST.map(ext =>
join(paths.absSrcPath, `${this.layoutDirectoryName}/index${ext}`),
),
],
});
this.watchers = watcherPaths.map(p => {
Expand Down Expand Up @@ -206,7 +209,10 @@ if (process.env.NODE_ENV === 'production') {
getLayoutFile() {
const { paths } = this.service;
for (const ext of EXT_LIST) {
const filePath = join(paths.absSrcPath, `layouts/index${ext}`);
const filePath = join(
paths.absSrcPath,
`${this.layoutDirectoryName}/index${ext}`,
);
if (existsSync(filePath)) {
return winPath(filePath);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/umi-build-dev/src/getConfig/configPlugins/singular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import assert from 'assert';

export default function(api) {
return {
name: 'singular',
validate(val) {
assert(
val === true || val === false,
`Configure item singular should be true or false, but got ${val}.`,
);
},
onChange() {
api.service.restart(/* why */ 'Configure item singular Changed.');
},
};
}
1 change: 0 additions & 1 deletion packages/umi-build-dev/src/getPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default function(opts = {}) {
'./plugins/output-path',
'./plugins/global-js',
'./plugins/global-css',
// './plugins/layout',
'./plugins/fastclick',
'./plugins/hd',
'./plugins/mock',
Expand Down
53 changes: 0 additions & 53 deletions packages/umi-build-dev/src/plugins/layout.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/umi-plugin-dva/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function(api) {
}

return globby
.sync('./models/**/*.{ts,js}', {
.sync(`./${config.singular ? 'model' : 'models'}/**/*.{ts,js}`, {
cwd,
})
.filter(p => !p.endsWith('.d.ts'))
Expand Down