Skip to content

Commit

Permalink
feat: support specify plugins in dev and build, Close #56
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Jan 19, 2018
1 parent d8c7851 commit 4d79f62
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/func-test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
'/dynamic': { spmb: 'b3333333333333', context: { title: '动态页' } },
},
plugins: [
'./plugin',
'./plugin1',
// 'umi-plugin-yunfengdie',
],
// disableServiceWorker: true,
Expand Down
3 changes: 0 additions & 3 deletions examples/func-test/plugin.js

This file was deleted.

3 changes: 3 additions & 0 deletions examples/func-test/plugin1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function generateEntry() {
console.log('generate entry in plugin1');
}
3 changes: 3 additions & 0 deletions examples/func-test/plugin2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function generateEntry() {
console.log('generate entry in plugin2');
}
10 changes: 5 additions & 5 deletions packages/umi-build-dev/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ export default function(opts = {}) {

// 获取用户配置
const { config } = getConfig(cwd);
const configPlugins = (config.plugins || []).map(p => {
const configPlugins = [
...(config.plugins || []),
...(pluginsFromOpts || []),
].map(p => {
return resolvePlugin(p, { cwd });
});
if (configPlugins.length) {
registerBabel(babel, {
only: [new RegExp(`(${configPlugins.join('|')})`)],
});
}
const plugins = resolvePlugins([
...configPlugins,
...(pluginsFromOpts || []),
]);
const plugins = resolvePlugins(configPlugins);

debug(`清理临时文件夹 ${paths.tmpDirPath}`);
rimraf(paths.absTmpDirPath);
Expand Down
10 changes: 5 additions & 5 deletions packages/umi-build-dev/src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export default function runDev(opts) {
return;
}

const configPlugins = (config.plugins || []).map(p => {
const configPlugins = [
...(config.plugins || []),
...(pluginsFromOpts || []),
].map(p => {
return resolvePlugin(p, {
cwd,
});
Expand All @@ -92,10 +95,7 @@ export default function runDev(opts) {
only: [new RegExp(`(${configPlugins.join('|')})`)],
});
}
const plugins = resolvePlugins([
...configPlugins,
...(pluginsFromOpts || []),
]);
const plugins = resolvePlugins(configPlugins);

// 生成入口文件
let watchEntry = null;
Expand Down
7 changes: 6 additions & 1 deletion packages/umi/src/scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import chalk from 'chalk';
import yParser from 'yargs-parser';
import build from '../build';

build().catch(e => {
const argv = yParser(process.argv.slice(2));

build({
plugins: argv.plugins ? argv.plugins.split(',') : [],
}).catch(e => {
console.error(chalk.red('构建出错'));
console.log(e);
});
8 changes: 6 additions & 2 deletions packages/umi/src/scripts/realDev.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { resolve } from 'path';
import yParser from 'yargs-parser';
import dev from '../dev';

const argv = yParser(process.argv.slice(2));

// 修复 Ctrl+C 时 dev server 没有正常退出的问题
process.on('SIGINT', () => {
process.exit(1);
});

dev();
dev({
plugins: argv.plugins ? argv.plugins.split(',') : [],
});

0 comments on commit 4d79f62

Please sign in to comment.