|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const assert = require('assert'); |
4 | | -const fs = require('fs'); |
5 | 4 |
|
6 | 5 | module.exports = function Methods(api, projectOptions) { |
7 | 6 |
|
| 7 | + const fixedPluginFile = require('./utils/fixedPluginFile.js'); |
| 8 | + |
8 | 9 | // 针对 vue plugin 的注册 |
9 | 10 | api.extendMethod('registerVuePlugin', { |
10 | 11 | description: '针对 vue-cli plugin 的注册方法.', |
@@ -86,51 +87,3 @@ module.exports = function Methods(api, projectOptions) { |
86 | 87 |
|
87 | 88 | }; |
88 | 89 |
|
89 | | -// 重新适配文件 |
90 | | -function fixedPluginFile(id, link) { |
91 | | - const newLink = link.replace(/\.js$/ig, '-for-micro-app.js'); |
92 | | - const jsText = fs.readFileSync(require.resolve(link), 'utf8'); |
93 | | - let newJsText = jsText |
94 | | - .replace(/registerCommand/gm, 'registerVueCommand') |
95 | | - .replace(new RegExp('vue-cli-service (\\w+)', 'gm'), 'micro-app-vue $1') |
96 | | - .replace(new RegExp('api.service.context', 'gm'), 'api.getCwd()') |
97 | | - .replace('const webpackConfig = api.resolveWebpackConfig()', [ |
98 | | - 'const _webpackConfig = api.resolveWebpackConfig()', |
99 | | - `const { webpackConfig } = api.applyPluginHooks('modifyWebpackConfig', { |
100 | | - args: args, |
101 | | - webpackConfig: _webpackConfig, |
102 | | - }); |
103 | | -
|
104 | | - if (!webpackConfig) { |
105 | | - api.logger.error('[Plugin] modifyWebpackConfig must return { webpackConfig }'); |
106 | | - return process.exit(1); |
107 | | - }`, |
108 | | - ].join('\n')) |
109 | | - ; |
110 | | - |
111 | | - if (id === 'vue-service:plugins-command-serve') { |
112 | | - // 注入事件 |
113 | | - newJsText = newJsText |
114 | | - .replace('api.service.devServerConfigFns.forEach(fn => fn(app, server))', [ |
115 | | - 'const config = api.serverConfig;', |
116 | | - "api.applyPluginHooks('onServerInit', { app, server, options, config });", |
117 | | - "api.applyPluginHooks('beforeServerEntry', { app, server, options, config });", |
118 | | - ].join('\n\n')) |
119 | | - .replace('before (app, server) {', [ |
120 | | - `after (app, server) { |
121 | | - const config = api.serverConfig; |
122 | | - api.applyPluginHooks('afterServerEntry', { app, server, options, config }); |
123 | | - api.applyPluginHooks('onServerInitDone', { app, server, options, config }); |
124 | | - projectDevServerOptions.after && projectDevServerOptions.after(app, server); |
125 | | - },`, |
126 | | - 'before (app, server) {', |
127 | | - ].join('\n')); |
128 | | - } |
129 | | - |
130 | | - |
131 | | - // TODO change module.exports.defeaultConfig |
132 | | - |
133 | | - fs.writeFileSync(newLink, newJsText, 'utf8'); |
134 | | - |
135 | | - return newLink; |
136 | | -} |
0 commit comments