-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheject.js
executable file
·97 lines (89 loc) · 3.05 KB
/
eject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const path = require('path');
const fs = require('fs');
const { resolveModule } = require('./resolve-module');
const DIR_NDS = __dirname;
// const DIR_NDS_MODULES = path.resolve(DIR_NDS, 'node_modules');
let _project = '.';
/**
* 弹出配置文件:nds-babel.js,该模块解析并导出本地安装的babel相关模块的路径,不可移植,需要开发者自行弹出:
* ```
* ~/app $ nds --eject
* ```
*/
function eject$nds_babel_js() {
const nds_babel_js_export = {
"loader": resolveModule('babel-loader'),
"options": {
"plugins": [
resolveModule('@babel/plugin-proposal-class-properties'),
],
"presets": [
[
resolveModule('@babel/preset-env'),
{
"targets": {
"esmodules": true
}
}
],
[
resolveModule('@babel/preset-typescript'),
],
]
}
};
let comment = `/*\n * Generated by node-dev-server:\n * $ nds --eject\n *\n * @author Develon (https://github.com/develon2015)\n */\n\n`;
let code = `${comment}module.exports = ${JSON.stringify(nds_babel_js_export, null, 4)};\n`;
fs.writeFileSync(path.resolve(_project, 'nds-babel.js'), code);
}
/**
* @deprecated
*/
function eject$babel_config_json() {
const babel_config_json = {
"plugins": [
resolveModule('@babel/plugin-proposal-class-properties'),
],
"presets": [
[
resolveModule('@babel/preset-env'),
{
"targets": {
"esmodules": true
}
}
],
[
resolveModule('@babel/preset-typescript'),
],
]
};
fs.writeFileSync(path.resolve(_project, 'babel.config.json'), JSON.stringify(babel_config_json, null, 2));
}
/**
* @deprecated
*/
function eject$webpack_config_js() {
const filename = 'webpack.config.js';
const webpack_config_js = fs.readFileSync(path.resolve(__dirname, './public/webpack.config.js')).toString('utf-8');
const replace = webpack_config_js.replace('`@BABEL_LOADER`', JSON.stringify(resolveModule('babel-loader')));
fs.writeFileSync(path.resolve(_project, filename), replace);
}
/**
* @deprecated
*/
function eject$tsconfig_json() {
const filename = 'tsconfig.json';
const tsconfig_json = fs.readFileSync(path.resolve(__dirname, './public/tsconfig.json.template')).toString('utf-8');
fs.writeFileSync(path.resolve(_project, filename), tsconfig_json);
}
function eject(project = process.cwd()) {
_project = project;
console.info('弹出配置文件!');
/* Warn: 不可移植的代码!*/ /*
eject$babel_config_json();
eject$webpack_config_js();
eject$tsconfig_json(); */
eject$nds_babel_js();
}
module.exports = eject;