@modern-js/plugin-docsite 1.0.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +1 -4
- package/dist/js/modern/features/constant.js +1 -1
- package/dist/js/modern/features/dev.js +2 -1
- package/dist/js/modern/features/index.js +2 -1
- package/dist/js/modern/features/utils/chokidar.js +2 -1
- package/dist/js/modern/features/utils/generate-files.js +2 -1
- package/dist/js/modern/features/utils/valid.js +1 -1
- package/dist/js/modern/features/utils/webpack.js +36 -17
- package/dist/js/modern/index.js +2 -2
- package/dist/js/node/features/constant.js +4 -2
- package/dist/js/node/features/dev.js +3 -1
- package/dist/js/node/features/index.js +6 -2
- package/dist/js/node/features/utils/chokidar.js +3 -1
- package/dist/js/node/features/utils/generate-files.js +18 -16
- package/dist/js/node/features/utils/valid.js +5 -2
- package/dist/js/node/features/utils/webpack.js +40 -20
- package/dist/js/node/index.js +1 -1
- package/package.json +10 -9
- package/src/features/constant.ts +1 -1
- package/src/features/dev.ts +2 -1
- package/src/features/index.ts +2 -1
- package/src/features/utils/chokidar.ts +2 -1
- package/src/features/utils/generate-files.ts +2 -1
- package/src/features/utils/valid.ts +1 -1
- package/src/features/utils/webpack.ts +44 -31
- package/src/index.ts +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
# @modern-js/plugin-docsite
|
2
2
|
|
3
|
+
## 1.1.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- fix missing dependencies bug
|
8
|
+
|
9
|
+
## 1.1.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 0fa83663: support more .env files
|
14
|
+
- Updated dependencies [6f7fe574]
|
15
|
+
- Updated dependencies [e4755134]
|
16
|
+
- Updated dependencies [0fa83663]
|
17
|
+
- Updated dependencies [19b4f79e]
|
18
|
+
- Updated dependencies [f594fbc8]
|
19
|
+
- Updated dependencies [d1fde77a]
|
20
|
+
- @modern-js/core@1.1.2
|
21
|
+
- @modern-js/webpack@1.1.2
|
22
|
+
- @modern-js/utils@1.1.2
|
23
|
+
|
24
|
+
## 1.1.0
|
25
|
+
|
26
|
+
### Minor Changes
|
27
|
+
|
28
|
+
- 96119db2: Relese v1.1.0### Patch Changes
|
29
|
+
|
30
|
+
- 6b802b2a: use path method from @modern-js/utils
|
31
|
+
- Updated dependencies [96119db2]
|
32
|
+
- @modern-js/core@1.1.0
|
33
|
+
- @modern-js/webpack@1.1.0
|
34
|
+
- @modern-js/utils@1.1.0
|
35
|
+
|
3
36
|
## 1.0.0
|
4
37
|
|
5
38
|
### Patch Changes
|
package/README.md
CHANGED
@@ -17,10 +17,7 @@
|
|
17
17
|
|
18
18
|
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
19
19
|
|
20
|
-
-
|
21
|
-
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
22
|
-
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
23
|
-
- [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
|
20
|
+
- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
|
24
21
|
|
25
22
|
## Getting Started
|
26
23
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import path from 'path';
|
2
|
+
import { fs, Import, logger } from '@modern-js/utils';
|
2
3
|
import { valid } from "./utils/valid";
|
3
4
|
const buildFeat = Import.lazy('./build', require);
|
4
5
|
const devFeat = Import.lazy('./dev', require);
|
@@ -10,7 +10,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
10
10
|
|
11
11
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
12
12
|
|
13
|
-
import
|
13
|
+
import path from 'path';
|
14
|
+
import { logger, fs } from '@modern-js/utils';
|
14
15
|
import matter from 'gray-matter';
|
15
16
|
import GithubSlugger from 'github-slugger';
|
16
17
|
import sortPaths from 'sort-paths';
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import path from 'path';
|
2
|
+
import { fs } from '@modern-js/utils';
|
2
3
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
3
4
|
import webpack from 'webpack';
|
4
5
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
@@ -23,27 +24,45 @@ export function generatorWebpackConfig(appDirectory, tmpDir, isDev) {
|
|
23
24
|
templateContent: fs.readFileSync(path.resolve(UTILS_STATIC, 'index.html.ejs'), 'utf8')
|
24
25
|
})]
|
25
26
|
};
|
26
|
-
|
27
|
+
const docsiteNodeModules = [// for yarn
|
28
|
+
path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), // for pnpm
|
29
|
+
path.resolve(path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), '../..')]; // maybe check if outside appDir or monorepoDir
|
30
|
+
|
31
|
+
config.resolve.modules = [...(config.resolve.modules || []), ...docsiteNodeModules];
|
27
32
|
config.resolve.alias['@assets'] = path.resolve(appDirectory, 'assets');
|
28
33
|
config.resolve.alias['@styles'] = path.resolve(appDirectory, 'styles'); // fix this since react-live relies on core-js@2
|
29
34
|
|
30
|
-
config.resolve.alias[`${path.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es';
|
31
|
-
|
32
|
-
|
33
|
-
if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
|
34
|
-
|
35
|
-
} else {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
config.resolve.alias[`${path.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es'; // const pkgJSON = JSON.parse(
|
36
|
+
// fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
|
37
|
+
// );
|
38
|
+
// if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
|
39
|
+
// (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
|
40
|
+
// } else {
|
41
|
+
// (config.resolve!.alias as Alias).react = path.resolve(
|
42
|
+
// __dirname,
|
43
|
+
// '../../../../../',
|
44
|
+
// 'node_modules',
|
45
|
+
// 'react',
|
46
|
+
// );
|
47
|
+
// }
|
48
|
+
// if (
|
49
|
+
// pkgJSON.dependencies['react-dom'] ||
|
50
|
+
// pkgJSON.devDependencies['react-dom']
|
51
|
+
// ) {
|
52
|
+
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
53
|
+
// 'node_modules/react-dom',
|
54
|
+
// );
|
55
|
+
// } else {
|
56
|
+
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
57
|
+
// __dirname,
|
58
|
+
// '../../../../../',
|
59
|
+
// 'node_modules',
|
60
|
+
// 'react-dom',
|
61
|
+
// );
|
62
|
+
// }
|
44
63
|
|
45
64
|
config.resolve.fallback = {
|
46
|
-
path:
|
65
|
+
path: require.resolve('path-browserify')
|
47
66
|
};
|
48
67
|
return config;
|
49
68
|
}
|
package/dist/js/modern/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Import
|
1
|
+
import { Import } from '@modern-js/utils';
|
2
2
|
const core = Import.lazy('@modern-js/core', require);
|
3
3
|
const features = Import.lazy('./features', require);
|
4
4
|
export default core.createPlugin(() => ({
|
@@ -39,7 +39,7 @@ export default core.createPlugin(() => ({
|
|
39
39
|
return {
|
40
40
|
name: 'docsite',
|
41
41
|
title: 'Run Docsite log',
|
42
|
-
taskPath:
|
42
|
+
taskPath: require.resolve("./build-task"),
|
43
43
|
params: []
|
44
44
|
};
|
45
45
|
}
|
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.UTILS_STATIC = exports.MDX_DEFAULT_RENDERER = exports.DOCS_RENDER_PATH = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
9
|
|
10
|
-
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
const UTILS_STATIC = _path.default.join(__dirname, '../../static');
|
11
13
|
|
12
14
|
exports.UTILS_STATIC = UTILS_STATIC;
|
13
15
|
const DOCS_RENDER_PATH = '/api/v1/docs/render';
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.dev = dev;
|
7
7
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
8
10
|
var _utils = require("@modern-js/utils");
|
9
11
|
|
10
12
|
var _webpack = _interopRequireDefault(require("webpack"));
|
@@ -26,7 +28,7 @@ async function dev(appDirectory, tmpDir, files, webpackConfig, isDev, port) {
|
|
26
28
|
port,
|
27
29
|
historyApiFallback: true,
|
28
30
|
static: {
|
29
|
-
directory:
|
31
|
+
directory: _path.default.resolve(appDirectory, 'assets'),
|
30
32
|
publicPath: '/assets'
|
31
33
|
}
|
32
34
|
}, compiler);
|
@@ -5,10 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.buildDocs = buildDocs;
|
7
7
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
8
10
|
var _utils = require("@modern-js/utils");
|
9
11
|
|
10
12
|
var _valid = require("./utils/valid");
|
11
13
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
12
16
|
const buildFeat = _utils.Import.lazy('./build', require);
|
13
17
|
|
14
18
|
const devFeat = _utils.Import.lazy('./dev', require);
|
@@ -31,7 +35,7 @@ async function buildDocs({
|
|
31
35
|
return;
|
32
36
|
}
|
33
37
|
|
34
|
-
const docsDir =
|
38
|
+
const docsDir = _path.default.resolve(appDirectory, 'docs');
|
35
39
|
|
36
40
|
if (!_utils.fs.pathExistsSync(docsDir)) {
|
37
41
|
return;
|
@@ -48,7 +52,7 @@ async function buildDocs({
|
|
48
52
|
return;
|
49
53
|
}
|
50
54
|
|
51
|
-
const tmpDir =
|
55
|
+
const tmpDir = _path.default.join(appDirectory, './node_modules/.modern-js/docs');
|
52
56
|
|
53
57
|
_utils.fs.ensureDirSync(tmpDir);
|
54
58
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.chokidarFile = chokidarFile;
|
7
7
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
8
10
|
var _utils = require("@modern-js/utils");
|
9
11
|
|
10
12
|
var _chokidar = _interopRequireDefault(require("chokidar"));
|
@@ -32,7 +34,7 @@ function chokidarFile(appDirectory, tmpDir, isDev) {
|
|
32
34
|
_utils.logger.info('changed, collect and rebuild docs');
|
33
35
|
|
34
36
|
const files = _glob.default.sync('**/*.{md,mdx}', {
|
35
|
-
cwd:
|
37
|
+
cwd: _path.default.resolve(appDirectory, 'docs'),
|
36
38
|
ignore: '**/_*'
|
37
39
|
});
|
38
40
|
|
@@ -15,6 +15,8 @@ var _camelCase2 = _interopRequireDefault(require("lodash/camelCase"));
|
|
15
15
|
|
16
16
|
var _startCase2 = _interopRequireDefault(require("lodash/startCase"));
|
17
17
|
|
18
|
+
var _path = _interopRequireDefault(require("path"));
|
19
|
+
|
18
20
|
var _utils = require("@modern-js/utils");
|
19
21
|
|
20
22
|
var _grayMatter = _interopRequireDefault(require("gray-matter"));
|
@@ -49,7 +51,7 @@ const loadTemplate = async (file, customPath = false) => {
|
|
49
51
|
if (customPath) {
|
50
52
|
result = await _utils.fs.readFile(file, 'utf-8');
|
51
53
|
} else {
|
52
|
-
result = await _utils.fs.readFile(
|
54
|
+
result = await _utils.fs.readFile(_path.default.join(_constant.UTILS_STATIC, file), 'utf-8');
|
53
55
|
}
|
54
56
|
|
55
57
|
return (0, _template2.default)(result, {
|
@@ -60,11 +62,11 @@ const loadTemplate = async (file, customPath = false) => {
|
|
60
62
|
// eslint-disable-next-line max-statements
|
61
63
|
async function handleFile(appDirectory, tmpDir, file, images) {
|
62
64
|
const moduleName = file.replace(/\.(md|mdx)$/, '');
|
63
|
-
const content = await _utils.fs.readFile(
|
65
|
+
const content = await _utils.fs.readFile(_path.default.resolve(appDirectory, 'docs', file));
|
64
66
|
const parsed = (0, _grayMatter.default)(content);
|
65
67
|
|
66
68
|
if (!parsed.data.title) {
|
67
|
-
parsed.data.title = (0, _startCase2.default)((0, _camelCase2.default)(
|
69
|
+
parsed.data.title = (0, _startCase2.default)((0, _camelCase2.default)(_path.default.basename(moduleName)));
|
68
70
|
}
|
69
71
|
|
70
72
|
const slugger = new _githubSlugger.default();
|
@@ -146,15 +148,15 @@ async function handleFile(appDirectory, tmpDir, file, images) {
|
|
146
148
|
} = node;
|
147
149
|
|
148
150
|
if (!url.startsWith('http')) {
|
149
|
-
const fullPath =
|
151
|
+
const fullPath = _path.default.resolve(_path.default.dirname(_path.default.resolve(appDirectory, 'docs', file)), url);
|
150
152
|
|
151
|
-
const relativePath =
|
153
|
+
const relativePath = _path.default.relative(_path.default.resolve(appDirectory, 'assets'), fullPath);
|
152
154
|
|
153
155
|
if (relativePath.startsWith('..')) {
|
154
156
|
_utils.logger.warn(`${url} referenced in ${file} is not under the "assets" folder`);
|
155
157
|
} else {
|
156
158
|
images.push(relativePath);
|
157
|
-
node.url = `/${
|
159
|
+
node.url = `/${_path.default.relative(_path.default.dirname(_path.default.resolve(appDirectory, 'docs', file)), _path.default.resolve(appDirectory, 'docs/assets', relativePath))}`;
|
158
160
|
}
|
159
161
|
}
|
160
162
|
});
|
@@ -165,19 +167,19 @@ async function handleFile(appDirectory, tmpDir, file, images) {
|
|
165
167
|
});
|
166
168
|
const totalExported = (0, _union2.default)(imported.map(n => n.id), exported.map(n => n.id));
|
167
169
|
|
168
|
-
const outputFile =
|
170
|
+
const outputFile = _path.default.resolve(tmpDir, `${moduleName}/mdx.jsx`);
|
169
171
|
|
170
172
|
await _utils.fs.outputFile(outputFile, _constant.MDX_DEFAULT_RENDERER + transpiled, {
|
171
173
|
encoding: 'utf8'
|
172
174
|
});
|
173
175
|
|
174
|
-
const pageFile =
|
176
|
+
const pageFile = _path.default.resolve(tmpDir, `${moduleName}/index.jsx`);
|
175
177
|
|
176
178
|
const pageTemplate = await loadTemplate('docs-page.jsx.tpl');
|
177
179
|
const pageContent = pageTemplate({
|
178
180
|
moduleName,
|
179
181
|
toc: JSON.stringify(toc),
|
180
|
-
relRoot:
|
182
|
+
relRoot: _path.default.relative(_path.default.dirname(outputFile), tmpDir),
|
181
183
|
imports: totalExported.length ? `import { ${totalExported.join(', ')} } from './mdx';` : '',
|
182
184
|
imported: totalExported.join(',')
|
183
185
|
});
|
@@ -197,16 +199,16 @@ async function generateFiles(appDirectory, tmpDir, files, isDev) {
|
|
197
199
|
const meta = await Promise.all(files.map(file => handleFile(appDirectory, tmpDir, file, images)));
|
198
200
|
const sorted = (0, _sortPaths.default)(meta, e => e.moduleName.endsWith('index') ? e.moduleName.replace(/index$/, '') : `${e.moduleName}/`, '/');
|
199
201
|
const routesTemplate = await loadTemplate('DocsRoutes.jsx.tpl');
|
200
|
-
await _utils.fs.outputFile(
|
202
|
+
await _utils.fs.outputFile(_path.default.resolve(tmpDir, 'DocsRoutes.jsx'), routesTemplate({
|
201
203
|
meta: sorted
|
202
204
|
}));
|
203
|
-
const pkgInfo = await _utils.fs.readJson(
|
205
|
+
const pkgInfo = await _utils.fs.readJson(_path.default.resolve(appDirectory, 'package.json'));
|
204
206
|
const entryTemplate = await loadTemplate('docs-entry.jsx.tpl');
|
205
|
-
await _utils.fs.outputFile(
|
207
|
+
await _utils.fs.outputFile(_path.default.resolve(tmpDir, 'docs-entry.jsx'), entryTemplate({
|
206
208
|
basename: isDev ? '/' : `${_constant.DOCS_RENDER_PATH}/${pkgInfo.name}/${pkgInfo.version}`
|
207
209
|
}));
|
208
|
-
await Promise.all(['DocsNav.jsx.tpl', 'DocsToc.jsx.tpl', 'docs.css'].map(async file => _utils.fs.copyFile(
|
209
|
-
await _utils.fs.outputJson(
|
210
|
+
await Promise.all(['DocsNav.jsx.tpl', 'DocsToc.jsx.tpl', 'docs.css'].map(async file => _utils.fs.copyFile(_path.default.resolve(_constant.UTILS_STATIC, file), _path.default.resolve(tmpDir, file.replace('.tpl', '')))));
|
211
|
+
await _utils.fs.outputJson(_path.default.resolve(tmpDir, 'meta.json'), sorted.map(({
|
210
212
|
title,
|
211
213
|
moduleName
|
212
214
|
}) => ({
|
@@ -215,7 +217,7 @@ async function generateFiles(appDirectory, tmpDir, files, isDev) {
|
|
215
217
|
})), {
|
216
218
|
spaces: 2
|
217
219
|
});
|
218
|
-
await _utils.fs.ensureDir(
|
219
|
-
await Promise.all(Array.from(new Set(images)).map(file => _utils.fs.copyFile(
|
220
|
+
await _utils.fs.ensureDir(_path.default.resolve(appDirectory, 'dist/docs/assets'));
|
221
|
+
await Promise.all(Array.from(new Set(images)).map(file => _utils.fs.copyFile(_path.default.resolve(appDirectory, 'assets', file), _path.default.resolve(appDirectory, 'dist/docs/assets', file))));
|
220
222
|
return sorted;
|
221
223
|
}
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.valid = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
9
|
|
10
10
|
var glob = _interopRequireWildcard(require("glob"));
|
11
11
|
|
@@ -15,11 +15,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
15
15
|
|
16
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17
17
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
18
20
|
const valid = ({
|
19
21
|
appDirectory,
|
20
22
|
docsDir
|
21
23
|
}) => {
|
22
|
-
const docsAbsPath =
|
24
|
+
const docsAbsPath = _path.default.join(appDirectory, docsDir);
|
25
|
+
|
23
26
|
const files = glob.sync(`${docsAbsPath}/**/*.{md,mdx}`);
|
24
27
|
|
25
28
|
if (!_utils.fs.existsSync(docsAbsPath) || files.length <= 0) {
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.generatorWebpackConfig = generatorWebpackConfig;
|
7
7
|
exports.runWebpack = runWebpack;
|
8
8
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
10
|
+
|
9
11
|
var _utils = require("@modern-js/utils");
|
10
12
|
|
11
13
|
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
@@ -25,40 +27,58 @@ function generatorWebpackConfig(appDirectory, tmpDir, isDev) {
|
|
25
27
|
mode: isDev ? 'development' : 'production',
|
26
28
|
context: tmpDir,
|
27
29
|
entry: {
|
28
|
-
index:
|
30
|
+
index: _path.default.resolve(tmpDir, 'docs-entry.jsx')
|
29
31
|
},
|
30
32
|
output: {
|
31
|
-
path:
|
33
|
+
path: _path.default.resolve(appDirectory, 'dist/docs')
|
32
34
|
},
|
33
35
|
resolve: originConfig.resolve || {
|
34
36
|
alias: {}
|
35
37
|
},
|
36
38
|
module: originConfig.module,
|
37
39
|
plugins: [...plugins, new _htmlWebpackPlugin.default({
|
38
|
-
templateContent: _utils.fs.readFileSync(
|
40
|
+
templateContent: _utils.fs.readFileSync(_path.default.resolve(_constant.UTILS_STATIC, 'index.html.ejs'), 'utf8')
|
39
41
|
})]
|
40
42
|
};
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
config.resolve.alias[`${_utils.path.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es';
|
46
|
-
const pkgJSON = JSON.parse(_utils.fs.readFileSync(_utils.path.join(appDirectory, 'package.json'), 'utf-8'));
|
43
|
+
const docsiteNodeModules = [// for yarn
|
44
|
+
_path.default.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), // for pnpm
|
45
|
+
_path.default.resolve(_path.default.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), '../..')]; // maybe check if outside appDir or monorepoDir
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
config.resolve.alias.react = _utils.path.resolve(__dirname, '../../../../../', 'node_modules', 'react');
|
52
|
-
}
|
47
|
+
config.resolve.modules = [...(config.resolve.modules || []), ...docsiteNodeModules];
|
48
|
+
config.resolve.alias['@assets'] = _path.default.resolve(appDirectory, 'assets');
|
49
|
+
config.resolve.alias['@styles'] = _path.default.resolve(appDirectory, 'styles'); // fix this since react-live relies on core-js@2
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
config.resolve.alias[`${_path.default.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es'; // const pkgJSON = JSON.parse(
|
52
|
+
// fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
|
53
|
+
// );
|
54
|
+
// if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
|
55
|
+
// (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
|
56
|
+
// } else {
|
57
|
+
// (config.resolve!.alias as Alias).react = path.resolve(
|
58
|
+
// __dirname,
|
59
|
+
// '../../../../../',
|
60
|
+
// 'node_modules',
|
61
|
+
// 'react',
|
62
|
+
// );
|
63
|
+
// }
|
64
|
+
// if (
|
65
|
+
// pkgJSON.dependencies['react-dom'] ||
|
66
|
+
// pkgJSON.devDependencies['react-dom']
|
67
|
+
// ) {
|
68
|
+
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
69
|
+
// 'node_modules/react-dom',
|
70
|
+
// );
|
71
|
+
// } else {
|
72
|
+
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
73
|
+
// __dirname,
|
74
|
+
// '../../../../../',
|
75
|
+
// 'node_modules',
|
76
|
+
// 'react-dom',
|
77
|
+
// );
|
78
|
+
// }
|
59
79
|
|
60
80
|
config.resolve.fallback = {
|
61
|
-
path:
|
81
|
+
path: require.resolve('path-browserify')
|
62
82
|
};
|
63
83
|
return config;
|
64
84
|
}
|
package/dist/js/node/index.js
CHANGED
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.1.2",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -25,15 +25,16 @@
|
|
25
25
|
},
|
26
26
|
"default": "./dist/js/treeshaking/index.js"
|
27
27
|
},
|
28
|
-
"./cli": "./dist/js/node/index.js"
|
28
|
+
"./cli": "./dist/js/node/index.js",
|
29
|
+
"./package.json": "./package.json"
|
29
30
|
},
|
30
31
|
"dependencies": {
|
31
32
|
"@babel/parser": "^7.15.2",
|
32
33
|
"@babel/runtime": "^7",
|
33
34
|
"@mdx-js/mdx": "^1.6.22",
|
34
35
|
"@mdx-js/react": "^1.6.22",
|
35
|
-
"@modern-js/utils": "^1.
|
36
|
-
"@modern-js/webpack": "^1.
|
36
|
+
"@modern-js/utils": "^1.1.2",
|
37
|
+
"@modern-js/webpack": "^1.1.2",
|
37
38
|
"antd": "^4.16.13",
|
38
39
|
"chokidar": "^3.5.2",
|
39
40
|
"core-js": "^3.17.2",
|
@@ -57,7 +58,7 @@
|
|
57
58
|
"webpack-dev-server": "^4.1.1"
|
58
59
|
},
|
59
60
|
"devDependencies": {
|
60
|
-
"@modern-js/module-tools-hooks": "^1.
|
61
|
+
"@modern-js/module-tools-hooks": "^1.1.1",
|
61
62
|
"@types/core-js": "^2.5.5",
|
62
63
|
"@types/github-slugger": "^1.3.0",
|
63
64
|
"@types/glob": "^7.1.4",
|
@@ -68,12 +69,12 @@
|
|
68
69
|
"@types/react-dom": "^17",
|
69
70
|
"@types/webpack-dev-server": "^4.1.0",
|
70
71
|
"typescript": "^4",
|
71
|
-
"@modern-js/core": "^1.
|
72
|
-
"@modern-js/plugin-testing": "^1.
|
73
|
-
"@modern-js/module-tools": "^1.
|
72
|
+
"@modern-js/core": "^1.1.2",
|
73
|
+
"@modern-js/plugin-testing": "^1.1.1",
|
74
|
+
"@modern-js/module-tools": "^1.1.1"
|
74
75
|
},
|
75
76
|
"peerDependencies": {
|
76
|
-
"@modern-js/core": "^1.
|
77
|
+
"@modern-js/core": "^1.1.2"
|
77
78
|
},
|
78
79
|
"sideEffects": false,
|
79
80
|
"modernConfig": {
|
package/src/features/constant.ts
CHANGED
package/src/features/dev.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import path from 'path';
|
2
|
+
import { logger } from '@modern-js/utils';
|
2
3
|
import webpack, { Configuration } from 'webpack';
|
3
4
|
import WebpackDevServer from 'webpack-dev-server';
|
4
5
|
import { chokidarFile } from './utils/chokidar';
|
package/src/features/index.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import path from 'path';
|
2
|
+
import { logger, fs } from '@modern-js/utils';
|
2
3
|
import matter from 'gray-matter';
|
3
4
|
import { startCase, camelCase, union, template, difference } from 'lodash';
|
4
5
|
import GithubSlugger from 'github-slugger';
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import path from 'path';
|
2
|
+
import { fs } from '@modern-js/utils';
|
2
3
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
3
4
|
import webpack, { Configuration, WebpackPluginInstance } from 'webpack';
|
4
5
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
@@ -34,10 +35,20 @@ export function generatorWebpackConfig(
|
|
34
35
|
}),
|
35
36
|
],
|
36
37
|
};
|
38
|
+
const docsiteNodeModules = [
|
39
|
+
// for yarn
|
40
|
+
path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')),
|
41
|
+
// for pnpm
|
42
|
+
path.resolve(
|
43
|
+
path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')),
|
44
|
+
'../..',
|
45
|
+
),
|
46
|
+
];
|
37
47
|
|
48
|
+
// maybe check if outside appDir or monorepoDir
|
38
49
|
config.resolve!.modules = [
|
39
50
|
...(config.resolve!.modules || []),
|
40
|
-
|
51
|
+
...docsiteNodeModules,
|
41
52
|
];
|
42
53
|
(config.resolve!.alias as Alias)['@assets'] = path.resolve(
|
43
54
|
appDirectory,
|
@@ -52,37 +63,39 @@ export function generatorWebpackConfig(
|
|
52
63
|
`${path.dirname(require.resolve('core-js'))}/fn`
|
53
64
|
] = 'core-js/es';
|
54
65
|
|
55
|
-
const pkgJSON = JSON.parse(
|
56
|
-
|
57
|
-
);
|
66
|
+
// const pkgJSON = JSON.parse(
|
67
|
+
// fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
|
68
|
+
// );
|
58
69
|
|
59
|
-
if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
|
60
|
-
|
61
|
-
} else {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
}
|
69
|
-
if (
|
70
|
-
|
71
|
-
|
72
|
-
) {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
} else {
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
70
|
+
// if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
|
71
|
+
// (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
|
72
|
+
// } else {
|
73
|
+
// (config.resolve!.alias as Alias).react = path.resolve(
|
74
|
+
// __dirname,
|
75
|
+
// '../../../../../',
|
76
|
+
// 'node_modules',
|
77
|
+
// 'react',
|
78
|
+
// );
|
79
|
+
// }
|
80
|
+
// if (
|
81
|
+
// pkgJSON.dependencies['react-dom'] ||
|
82
|
+
// pkgJSON.devDependencies['react-dom']
|
83
|
+
// ) {
|
84
|
+
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
85
|
+
// 'node_modules/react-dom',
|
86
|
+
// );
|
87
|
+
// } else {
|
88
|
+
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
89
|
+
// __dirname,
|
90
|
+
// '../../../../../',
|
91
|
+
// 'node_modules',
|
92
|
+
// 'react-dom',
|
93
|
+
// );
|
94
|
+
// }
|
84
95
|
|
85
|
-
config.resolve!.fallback = {
|
96
|
+
config.resolve!.fallback = {
|
97
|
+
path: require.resolve('path-browserify'),
|
98
|
+
};
|
86
99
|
return config;
|
87
100
|
}
|
88
101
|
|
package/src/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Import
|
1
|
+
import { Import } from '@modern-js/utils';
|
2
2
|
|
3
3
|
const core: typeof import('@modern-js/core') = Import.lazy(
|
4
4
|
'@modern-js/core',
|
@@ -33,7 +33,7 @@ export default core.createPlugin(
|
|
33
33
|
return {
|
34
34
|
name: 'docsite',
|
35
35
|
title: 'Run Docsite log',
|
36
|
-
taskPath:
|
36
|
+
taskPath: require.resolve('./build-task'),
|
37
37
|
params: [],
|
38
38
|
};
|
39
39
|
},
|