diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ceb275c..2d9a4f46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ -## [1.0.9](https://github.com/luoxue-victor/learn_webpack/compare/v1.2.3...v1.0.9) (2019-12-24) +## [1.0.9](https://github.com/luoxue-victor/learn_webpack/compare/v1.2.3...v1.0.9) (2019-12-25) ### 🐛 Bug 修复 范围|描述|commitId --|--|-- - package | 升级插件版本| [dea53d5](https://github.com/luoxue-victor/learn_webpack/commit/dea53d5) + package | 升级插件版本| [dea53d5](https://github.com/luoxue-victor/learn_webpack/commit/dea53d5) webpack-box | 降低复杂度| [907ef27](https://github.com/luoxue-victor/learn_webpack/commit/907ef27) ### 📝 文档 范围|描述|commitId diff --git a/README.md b/README.md index 3c982a5a..8354593c 100644 --- a/README.md +++ b/README.md @@ -154,15 +154,15 @@ webpack-box server:gql # graphql-server - [CaseSensitivePaths 严格区分大小写](./packages/webpack-box/config/caseSensitivePaths.js) - [dashboard 增加仪表盘配置](./packages/webpack-box/config/dashboard.js) - [devServer.before 在devServer中添加中间件](./packages/webpack-box/config/devServerBefore.js) -- [eslint-loader 配置](./packages/webpack-box/config/eslintLoader.js) - [提取 manifest](./packages/webpack-box/config/manifest.js) - [optimization 优化配置](./packages/webpack-box/config/optimization.js) - [样式表配置](./packages/webpack-box/config/style.js) -- [stylelint 配置](./packages/webpack-box/config/styleLintPlugin.js) - [设置 style 全局变量](./packages/webpack-box/config/styleResourcesLoader.js) - [多线程配置](./packages/webpack-box/config/threadLoader.js) - [tslint 配置](./packages/webpack-box/config/tslintPlugin.js) +- [eslint-loader 配置](./packages/eslint/webpack-chain.config.js) - [react 配置](./packages/react/webpack-chain.config.js) +- [stylelint 配置](./packages/stylelint/webpack-chain.config.js) diff --git a/packages/webpack-box/commands/lint.js b/packages/eslint/command.config.js similarity index 81% rename from packages/webpack-box/commands/lint.js rename to packages/eslint/command.config.js index 5e9d5cb9..2578a14f 100644 --- a/packages/webpack-box/commands/lint.js +++ b/packages/eslint/command.config.js @@ -1,12 +1,12 @@ module.exports = function({ injectCommand, api }) { injectCommand(function({ program, cleanArgs, boxConfig }) { program - .command('lint [type]') + .command('lint eslint') .description('修复lint') .action(async (name, cmd) => { const options = cleanArgs(cmd) const args = Object.assign(options, { name }, boxConfig) - require('../build/lint')(args, api) + require('./lint')({ args, api }) }) }) } diff --git a/packages/webpack-box/config/eslintLoader.js b/packages/eslint/webpack-chain.config.js similarity index 89% rename from packages/webpack-box/config/eslintLoader.js rename to packages/eslint/webpack-chain.config.js index 67488122..1e62ba1d 100644 --- a/packages/webpack-box/config/eslintLoader.js +++ b/packages/eslint/webpack-chain.config.js @@ -1,8 +1,6 @@ // [eslint-loader 配置] module.exports = ({ config, options: { eslint: { lintOnSave = false, extensions } }, api }) => { - const path = require('path') - const eslintOptionsPath = path.join('..', 'packages', 'eslint', 'eslintOptions') - extensions = extensions || require(eslintOptionsPath).extensions(api) + extensions = extensions || require('./eslintOptions').extensions(api) return () => { if (!lintOnSave) return const path = require('path') diff --git a/packages/stylelint/command.config.js b/packages/stylelint/command.config.js new file mode 100644 index 00000000..ab1574bd --- /dev/null +++ b/packages/stylelint/command.config.js @@ -0,0 +1,12 @@ +module.exports = function({ injectCommand, api }) { + injectCommand(function({ program, cleanArgs, boxConfig }) { + program + .command('lint stylelint') + .description('修复lint') + .action(async (name, cmd) => { + const options = cleanArgs(cmd) + const args = Object.assign(options, { name }, boxConfig) + require('./lint')({ args, api }) + }) + }) +} diff --git a/packages/webpack-box/config/styleLintPlugin.js b/packages/stylelint/webpack-chain.config.js similarity index 100% rename from packages/webpack-box/config/styleLintPlugin.js rename to packages/stylelint/webpack-chain.config.js diff --git a/packages/tslint/command.config.js b/packages/tslint/command.config.js new file mode 100644 index 00000000..9e77c8fa --- /dev/null +++ b/packages/tslint/command.config.js @@ -0,0 +1,12 @@ +module.exports = function({ injectCommand, api }) { + injectCommand(function({ program, cleanArgs, boxConfig }) { + program + .command('lint tslint') + .description('修复lint') + .action(async (name, cmd) => { + const options = cleanArgs(cmd) + const args = Object.assign(options, { name }, boxConfig) + require('./lint')({ args, api }) + }) + }) +} diff --git a/packages/webpack-box/api/CommandAPI.js b/packages/webpack-box/api/CommandAPI.js index 8450a2de..404c2c17 100644 --- a/packages/webpack-box/api/CommandAPI.js +++ b/packages/webpack-box/api/CommandAPI.js @@ -31,12 +31,22 @@ module.exports.getAllCommands = function() { const localCwdPath = path.join(__dirname, '..', 'commands') const localCwdNames = [...fs.readdirSync(localCwdPath)] const cwdFns = [] - const { getConfigsByName } = require('../util/getLocalConfigByPath') localCwdNames.forEach(name => { const cwdPath = path.join(localCwdPath, name) cwdFns.push(require(cwdPath)) }) - // cwdFns.push(...getConfigsByName('packages', 'command.config.js')) + + const { getAllPluginIdOfPackageJson } = require('@pkb/shared-utils') + + getAllPluginIdOfPackageJson().forEach(id => { + const command = `${id}/command.config.js` + try { + const cwd = require(command) + cwdFns.push(require(cwd)) + } catch (error) { + console.log(`没有 ${command}`) + } + }) return cwdFns } diff --git a/packages/webpack-box/build/base.js b/packages/webpack-box/build/base.js index 9d988fff..a6508a14 100644 --- a/packages/webpack-box/build/base.js +++ b/packages/webpack-box/build/base.js @@ -21,7 +21,7 @@ module.exports = (options) => { const config = require(pluginWebpackChainPath) configs.push(config) } catch (error) { - console.log(error) + console.log(`没有 ${pluginWebpackChainPath}`) } }) diff --git a/packages/webpack-box/build/lint.js b/packages/webpack-box/build/lint.js deleted file mode 100644 index 1ccce1ab..00000000 --- a/packages/webpack-box/build/lint.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function (args, api) { - require(`pk-cli-plugin-${args.name}/lint`)({ args, api }) -} diff --git a/packages/webpack-box/package.json b/packages/webpack-box/package.json index d9878424..d8d3df54 100644 --- a/packages/webpack-box/package.json +++ b/packages/webpack-box/package.json @@ -74,9 +74,6 @@ "mockjs": "^1.1.0", "mongoose": "^5.2.15", "ora": "^4.0.3", - "pk-cli-plugin-eslint": "^1.2.2", - "pk-cli-plugin-stylelint": "^1.2.1", - "pk-cli-plugin-tslint": "^1.2.2", "postcss-loader": "^3.0.0", "postcss-px-to-viewport": "^1.1.1", "preload-webpack-plugin": "^3.0.0-beta.4",