@modern-js/module-tools 1.5.8 → 1.6.1
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 +41 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +55 -28
- package/dist/js/modern/features/build/bundle/index.js +9 -0
- package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
- package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
- package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -56
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -71
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +10 -10
- package/dist/js/modern/features/build/bundleless/index.js +23 -0
- package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
- package/dist/js/modern/features/build/bundleless/style.js +266 -0
- package/dist/js/modern/features/build/constants.js +94 -59
- package/dist/js/modern/features/build/error.js +150 -0
- package/dist/js/modern/features/build/index.js +87 -18
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +301 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +39 -136
- package/dist/js/modern/index.js +3 -1
- package/dist/js/modern/locale/en.js +5 -3
- package/dist/js/modern/locale/zh.js +5 -3
- package/dist/js/modern/schema/build-config.js +111 -0
- package/dist/js/modern/schema/index.js +2 -1
- package/dist/js/modern/schema/output.js +18 -9
- package/dist/js/modern/schema/source.js +2 -10
- package/dist/js/modern/schema/tools.js +6 -0
- package/dist/js/modern/schema/types.js +0 -0
- package/dist/js/modern/utils/babel.js +4 -1
- package/dist/js/modern/utils/constants.js +3 -0
- package/dist/js/modern/utils/copy.js +2 -2
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +62 -29
- package/dist/js/node/features/build/bundle/index.js +23 -0
- package/dist/js/node/features/build/bundle/runRollup.js +174 -0
- package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
- package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -56
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +58 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
- package/dist/js/node/features/build/bundleless/index.js +40 -0
- package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
- package/dist/js/node/features/build/bundleless/style.js +299 -0
- package/dist/js/node/features/build/constants.js +115 -67
- package/dist/js/node/features/build/error.js +175 -0
- package/dist/js/node/features/build/index.js +104 -18
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +330 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +48 -145
- package/dist/js/node/index.js +20 -1
- package/dist/js/node/locale/en.js +5 -3
- package/dist/js/node/locale/zh.js +5 -3
- package/dist/js/node/schema/build-config.js +120 -0
- package/dist/js/node/schema/index.js +3 -1
- package/dist/js/node/schema/output.js +20 -9
- package/dist/js/node/schema/source.js +2 -10
- package/dist/js/node/schema/tools.js +13 -0
- package/dist/js/node/schema/types.js +0 -0
- package/dist/js/node/utils/babel.js +4 -1
- package/dist/js/node/utils/constants.js +11 -0
- package/dist/js/node/utils/copy.js +1 -1
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/commands/build.d.ts +12 -12
- package/dist/types/features/build/bundle/index.d.ts +3 -0
- package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
- package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
- package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
- package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
- package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
- package/dist/types/features/build/bundleless/index.d.ts +4 -0
- package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
- package/dist/types/features/build/bundleless/style.d.ts +25 -0
- package/dist/types/features/build/constants.d.ts +17 -13
- package/dist/types/features/build/error.d.ts +33 -0
- package/dist/types/features/build/index.d.ts +12 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/normalize.d.ts +19 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +10 -31
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/schema/build-config.d.ts +197 -0
- package/dist/types/schema/index.d.ts +184 -18
- package/dist/types/schema/output.d.ts +188 -10
- package/dist/types/schema/source.d.ts +2 -11
- package/dist/types/schema/tools.d.ts +6 -0
- package/dist/types/schema/types.d.ts +46 -0
- package/dist/types/types.d.ts +29 -28
- package/dist/types/utils/babel.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +2 -0
- package/package.json +23 -9
- package/dist/js/modern/features/build/build-watch.js +0 -101
- package/dist/js/modern/features/build/build.js +0 -123
- package/dist/js/modern/tasks/build-source-code.js +0 -208
- package/dist/js/modern/tasks/build-style.js +0 -169
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -162
- package/dist/js/modern/tasks/build-watch-style.js +0 -216
- package/dist/js/modern/tasks/constants.js +0 -1
- package/dist/js/node/features/build/build-watch.js +0 -121
- package/dist/js/node/features/build/build.js +0 -143
- package/dist/js/node/tasks/build-source-code.js +0 -234
- package/dist/js/node/tasks/build-style.js +0 -184
- package/dist/js/node/tasks/build-watch-source-code.js +0 -174
- package/dist/js/node/tasks/build-watch-style.js +0 -233
- package/dist/js/node/tasks/constants.js +0 -8
- package/dist/types/features/build/build-watch.d.ts +0 -3
- package/dist/types/features/build/build.d.ts +0 -3
- package/dist/types/tasks/build-source-code.d.ts +0 -25
- package/dist/types/tasks/build-style.d.ts +0 -1
- package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
- package/dist/types/tasks/build-watch-style.d.ts +0 -1
- package/dist/types/tasks/constants.d.ts +0 -1
- package/dist/types/tasks/copy-assets.d.ts +0 -1
- package/dist/types/tasks/generator-dts/index.d.ts +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startRollup = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _typescript = _interopRequireDefault(require("typescript"));
|
|
11
|
+
|
|
12
|
+
var _rollupPluginHashbang = _interopRequireDefault(require("rollup-plugin-hashbang"));
|
|
13
|
+
|
|
14
|
+
var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
|
|
15
|
+
|
|
16
|
+
var _error = require("../error");
|
|
17
|
+
|
|
18
|
+
var _utils = require("../utils");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
// Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
|
|
33
|
+
const loadCompilerOptions = tsconfig => {
|
|
34
|
+
if (!tsconfig) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const configFile = _typescript.default.readConfigFile(tsconfig, _typescript.default.sys.readFile);
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
options
|
|
42
|
+
} = _typescript.default.parseJsonConfigFileContent(configFile.config, _typescript.default.sys, './');
|
|
43
|
+
|
|
44
|
+
return options;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const dtsPlugin = require('rollup-plugin-dts');
|
|
48
|
+
|
|
49
|
+
const getRollupConfig = async (api, options) => {
|
|
50
|
+
const {
|
|
51
|
+
appDirectory
|
|
52
|
+
} = api.useAppContext();
|
|
53
|
+
const {
|
|
54
|
+
output: {
|
|
55
|
+
path: distPath = 'dist'
|
|
56
|
+
}
|
|
57
|
+
} = api.useResolvedConfigContext();
|
|
58
|
+
const {
|
|
59
|
+
outputPath,
|
|
60
|
+
bundleOptions,
|
|
61
|
+
tsconfig
|
|
62
|
+
} = options;
|
|
63
|
+
|
|
64
|
+
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
65
|
+
|
|
66
|
+
const compilerOptions = loadCompilerOptions(tsconfig);
|
|
67
|
+
const dtsOptions = {
|
|
68
|
+
entry: bundleOptions.entry
|
|
69
|
+
};
|
|
70
|
+
const ignoreFiles = {
|
|
71
|
+
name: 'ignore-files',
|
|
72
|
+
|
|
73
|
+
load(id) {
|
|
74
|
+
if (!/\.(js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(id)) {
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
inputConfig: {
|
|
84
|
+
input: dtsOptions.entry,
|
|
85
|
+
external: bundleOptions.externals,
|
|
86
|
+
|
|
87
|
+
onwarn(warning, handler) {
|
|
88
|
+
if (warning.code === 'UNRESOLVED_IMPORT' || warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EMPTY_BUNDLE') {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
handler(warning);
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
plugins: [(0, _rollupPluginHashbang.default)(), (0, _pluginJson.default)(), ignoreFiles, dtsPlugin.default({
|
|
96
|
+
// use external to prevent them which come from node_modules from be bundled.
|
|
97
|
+
respectExternal: true,
|
|
98
|
+
compilerOptions: _objectSpread(_objectSpread({}, compilerOptions), {}, {
|
|
99
|
+
baseUrl: _path.default.resolve(compilerOptions.baseUrl || '.'),
|
|
100
|
+
// Ensure ".d.ts" modules are generated
|
|
101
|
+
declaration: true,
|
|
102
|
+
// Skip ".js" generation
|
|
103
|
+
noEmit: false,
|
|
104
|
+
emitDeclarationOnly: true,
|
|
105
|
+
// Skip code generation when error occurs
|
|
106
|
+
noEmitOnError: true,
|
|
107
|
+
// Avoid extra work
|
|
108
|
+
checkJs: false,
|
|
109
|
+
declarationMap: false,
|
|
110
|
+
skipLibCheck: true,
|
|
111
|
+
preserveSymlinks: false,
|
|
112
|
+
// Ensure we can parse the latest code
|
|
113
|
+
target: _typescript.default.ScriptTarget.ESNext
|
|
114
|
+
})
|
|
115
|
+
})].filter(Boolean)
|
|
116
|
+
},
|
|
117
|
+
outputConfig: {
|
|
118
|
+
dir: distDir,
|
|
119
|
+
format: 'esm',
|
|
120
|
+
exports: 'named'
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
async function runRollup(options, context) {
|
|
126
|
+
try {
|
|
127
|
+
const {
|
|
128
|
+
rollup
|
|
129
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('rollup')));
|
|
130
|
+
const bundle = await rollup(options.inputConfig);
|
|
131
|
+
await bundle.write(options.outputConfig);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
if (e instanceof Error) {
|
|
134
|
+
throw new _error.InternalDTSError(e, _objectSpread({
|
|
135
|
+
buildType: 'bundle'
|
|
136
|
+
}, context));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function watchRollup(options) {
|
|
142
|
+
const {
|
|
143
|
+
watch
|
|
144
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('rollup')));
|
|
145
|
+
const titleText = '[Bundle:DTS]';
|
|
146
|
+
watch(_objectSpread(_objectSpread({}, options.inputConfig), {}, {
|
|
147
|
+
plugins: options.inputConfig.plugins,
|
|
148
|
+
output: options.outputConfig
|
|
149
|
+
})).on('event', event => {
|
|
150
|
+
if (event.code === 'START') {
|
|
151
|
+
console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Log));
|
|
152
|
+
} else if (event.code === 'BUNDLE_END') {
|
|
153
|
+
console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Success));
|
|
154
|
+
} else if (event.code === 'ERROR') {// this is dts rollup plugin bug, error not complete message
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const startRollup = async (api, options) => {
|
|
160
|
+
if (options.enableDts) {
|
|
161
|
+
const config = await getRollupConfig(api, options);
|
|
162
|
+
|
|
163
|
+
if (options.watch) {
|
|
164
|
+
watchRollup(config);
|
|
165
|
+
} else {
|
|
166
|
+
await runRollup(config, {
|
|
167
|
+
target: options.target,
|
|
168
|
+
format: options.format
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
exports.startRollup = startRollup;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runSpeedy = exports.getDefine = exports.getAlias = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _speedyCore = require("@speedy-js/speedy-core");
|
|
11
|
+
|
|
12
|
+
var _speedyPluginEs = require("@speedy-js/speedy-plugin-es5");
|
|
13
|
+
|
|
14
|
+
var _utils = require("@modern-js/utils");
|
|
15
|
+
|
|
16
|
+
var _error = require("../error");
|
|
17
|
+
|
|
18
|
+
var _utils2 = require("../utils");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
const getAlias = api => {
|
|
29
|
+
const {
|
|
30
|
+
appDirectory,
|
|
31
|
+
srcDirectory
|
|
32
|
+
} = api.useAppContext();
|
|
33
|
+
const {
|
|
34
|
+
source
|
|
35
|
+
} = api.useResolvedConfigContext(); // TODO: maybe check tsconfig `paths`
|
|
36
|
+
|
|
37
|
+
const defaultAlias = {
|
|
38
|
+
'@': srcDirectory
|
|
39
|
+
};
|
|
40
|
+
const alias = (0, _utils.applyOptionsChain)(defaultAlias, source === null || source === void 0 ? void 0 : source.alias);
|
|
41
|
+
return Object.keys(alias).reduce((o, name) => {
|
|
42
|
+
return _objectSpread(_objectSpread({}, o), {}, {
|
|
43
|
+
[name]: (0, _utils.ensureAbsolutePath)(appDirectory, alias[name])
|
|
44
|
+
});
|
|
45
|
+
}, {});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.getAlias = getAlias;
|
|
49
|
+
|
|
50
|
+
const getDefine = api => {
|
|
51
|
+
const {
|
|
52
|
+
source: {
|
|
53
|
+
envVars,
|
|
54
|
+
globalVars
|
|
55
|
+
}
|
|
56
|
+
} = api.useResolvedConfigContext();
|
|
57
|
+
const envVarsDefine = [...(envVars || [])].reduce((memo, name) => {
|
|
58
|
+
memo[`process.env.${name}`] = JSON.stringify(process.env[name]);
|
|
59
|
+
return memo;
|
|
60
|
+
}, {});
|
|
61
|
+
const globalVarsDefine = Object.keys(globalVars || {}).reduce((memo, name) => {
|
|
62
|
+
memo[name] = globalVars ? JSON.stringify(globalVars[name]) : '';
|
|
63
|
+
return memo;
|
|
64
|
+
}, {});
|
|
65
|
+
return _objectSpread(_objectSpread({}, envVarsDefine), globalVarsDefine);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.getDefine = getDefine;
|
|
69
|
+
|
|
70
|
+
const getStyleOptionFromModern = async api => {
|
|
71
|
+
const runner = api.useHookRunners();
|
|
72
|
+
const {
|
|
73
|
+
appDirectory
|
|
74
|
+
} = api.useAppContext();
|
|
75
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
76
|
+
const lessOption = await runner.moduleLessConfig({
|
|
77
|
+
modernConfig
|
|
78
|
+
}, {
|
|
79
|
+
onLast: async _ => undefined
|
|
80
|
+
});
|
|
81
|
+
const sassOption = await runner.moduleSassConfig({
|
|
82
|
+
modernConfig
|
|
83
|
+
}, {
|
|
84
|
+
onLast: async _ => undefined
|
|
85
|
+
});
|
|
86
|
+
const tailwindPlugin = await runner.moduleTailwindConfig({
|
|
87
|
+
modernConfig
|
|
88
|
+
}, {
|
|
89
|
+
onLast: async _ => undefined
|
|
90
|
+
});
|
|
91
|
+
const postcssOption = (0, _utils2.getPostcssOption)(appDirectory, modernConfig);
|
|
92
|
+
|
|
93
|
+
if (tailwindPlugin) {
|
|
94
|
+
var _postcssOption$plugin;
|
|
95
|
+
|
|
96
|
+
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
less: lessOption === null || lessOption === void 0 ? void 0 : lessOption.lessOption,
|
|
101
|
+
sass: sassOption,
|
|
102
|
+
postcss: _objectSpread(_objectSpread({}, postcssOption.options), {}, {
|
|
103
|
+
plugins: postcssOption.plugins
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const runSpeedy = async (api, config) => {
|
|
109
|
+
const {
|
|
110
|
+
appDirectory
|
|
111
|
+
} = api.useAppContext();
|
|
112
|
+
const {
|
|
113
|
+
output: {
|
|
114
|
+
path: distPath = 'dist'
|
|
115
|
+
},
|
|
116
|
+
tools: {
|
|
117
|
+
speedy: userSpeedyConfig
|
|
118
|
+
}
|
|
119
|
+
} = api.useResolvedConfigContext();
|
|
120
|
+
const {
|
|
121
|
+
target,
|
|
122
|
+
watch,
|
|
123
|
+
bundleOptions,
|
|
124
|
+
outputPath,
|
|
125
|
+
format,
|
|
126
|
+
sourceMap
|
|
127
|
+
} = config;
|
|
128
|
+
const {
|
|
129
|
+
entry,
|
|
130
|
+
platform,
|
|
131
|
+
splitting,
|
|
132
|
+
minify,
|
|
133
|
+
externals
|
|
134
|
+
} = bundleOptions;
|
|
135
|
+
|
|
136
|
+
const distDir = _path.default.join(appDirectory, distPath, outputPath);
|
|
137
|
+
|
|
138
|
+
const titleText = `[Bundle:Speedy:${format}_${target}]`;
|
|
139
|
+
const style = await getStyleOptionFromModern(api);
|
|
140
|
+
const alias = getAlias(api);
|
|
141
|
+
const define = getDefine(api);
|
|
142
|
+
|
|
143
|
+
const watchPlugin = () => {
|
|
144
|
+
return {
|
|
145
|
+
name: 'watch-plugin',
|
|
146
|
+
|
|
147
|
+
apply(compiler) {
|
|
148
|
+
compiler.hooks.watchChange.tap('watch-plugin', async () => {
|
|
149
|
+
console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const plugins = target === 'es5' ? [(0, _speedyPluginEs.es5InputPlugin)()] : [];
|
|
157
|
+
plugins.push(watchPlugin());
|
|
158
|
+
const internalSpeedyConfig = {
|
|
159
|
+
command: 'build',
|
|
160
|
+
mode: 'production',
|
|
161
|
+
html: false,
|
|
162
|
+
preset: 'webapp',
|
|
163
|
+
// support css and json
|
|
164
|
+
platform,
|
|
165
|
+
watch,
|
|
166
|
+
input: entry,
|
|
167
|
+
target,
|
|
168
|
+
clearScreen: false,
|
|
169
|
+
output: {
|
|
170
|
+
path: distDir,
|
|
171
|
+
format,
|
|
172
|
+
splitting,
|
|
173
|
+
filename: '[name]'
|
|
174
|
+
},
|
|
175
|
+
style,
|
|
176
|
+
resolve: {
|
|
177
|
+
alias
|
|
178
|
+
},
|
|
179
|
+
define,
|
|
180
|
+
sourceMap,
|
|
181
|
+
minify,
|
|
182
|
+
external: externals,
|
|
183
|
+
plugins
|
|
184
|
+
};
|
|
185
|
+
const speedyConfig = (0, _utils.applyOptionsChain)(internalSpeedyConfig, userSpeedyConfig);
|
|
186
|
+
const compiler = await _speedyCore.SpeedyBundler.create(speedyConfig);
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
if (watch) {
|
|
190
|
+
console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await compiler.build();
|
|
194
|
+
} catch (e) {
|
|
195
|
+
/**
|
|
196
|
+
* in watch mode
|
|
197
|
+
* use speedy watch log
|
|
198
|
+
*/
|
|
199
|
+
if (e instanceof Error) {
|
|
200
|
+
throw new _error.InternalBuildError(e, {
|
|
201
|
+
target,
|
|
202
|
+
format,
|
|
203
|
+
buildType: 'bundle'
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
exports.runSpeedy = runSpeedy;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.copyStaticAssets = void 0;
|
|
7
|
+
|
|
3
8
|
var path = _interopRequireWildcard(require("path"));
|
|
4
9
|
|
|
5
10
|
var _utils = require("@modern-js/utils");
|
|
@@ -8,13 +13,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
8
13
|
|
|
9
14
|
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; }
|
|
10
15
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
14
|
-
|
|
15
|
-
const copyUtils = _utils.Import.lazy('../utils/copy', require);
|
|
16
|
+
const copyUtils = _utils.Import.lazy('../../../utils/copy', require);
|
|
16
17
|
|
|
17
|
-
const STYLE_DIRS = 'styles';
|
|
18
18
|
const SRC_DIRS = 'src';
|
|
19
19
|
|
|
20
20
|
const copyAssets = ({
|
|
@@ -38,11 +38,13 @@ const copyAssets = ({
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const watchAssets = ({
|
|
41
|
+
const watchAssets = (api, {
|
|
42
42
|
targetDir,
|
|
43
43
|
outputDir
|
|
44
44
|
}) => {
|
|
45
|
-
|
|
45
|
+
const appContext = api.useAppContext();
|
|
46
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
47
|
+
(0, _utils.watch)(`${targetDir}/**/*.*`, async ({
|
|
46
48
|
changeType,
|
|
47
49
|
changedFilePath
|
|
48
50
|
}) => {
|
|
@@ -57,74 +59,53 @@ const watchAssets = ({
|
|
|
57
59
|
const file = path.relative(targetDir, changedFilePath);
|
|
58
60
|
|
|
59
61
|
_utils.fs.copyFileSync(changedFilePath, path.resolve(outputDir, file));
|
|
62
|
+
|
|
63
|
+
await copyUtils.copyTask({
|
|
64
|
+
modernConfig,
|
|
65
|
+
appContext
|
|
66
|
+
});
|
|
60
67
|
}, ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']);
|
|
61
68
|
};
|
|
62
69
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const config = processArgv({});
|
|
70
|
+
const copyStaticAssets = async (api, config) => {
|
|
71
|
+
var _bundlelessOptions$so;
|
|
72
|
+
|
|
73
|
+
const appContext = api.useAppContext();
|
|
74
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
69
75
|
const {
|
|
70
76
|
appDirectory
|
|
71
77
|
} = appContext;
|
|
72
78
|
const {
|
|
73
|
-
|
|
74
|
-
assetsPath = 'styles',
|
|
75
|
-
path: outputPath = 'dist'
|
|
79
|
+
path: distPath = 'dist'
|
|
76
80
|
} = modernConfig.output;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const {
|
|
82
|
+
outputPath,
|
|
83
|
+
bundlelessOptions
|
|
84
|
+
} = config;
|
|
85
|
+
const {
|
|
86
|
+
static: {
|
|
87
|
+
path: staticPath = './'
|
|
88
|
+
} = {
|
|
89
|
+
path: './'
|
|
90
|
+
}
|
|
91
|
+
} = bundlelessOptions;
|
|
92
|
+
const srcDir = path.join(appDirectory, (_bundlelessOptions$so = bundlelessOptions.sourceDir) !== null && _bundlelessOptions$so !== void 0 ? _bundlelessOptions$so : SRC_DIRS);
|
|
93
|
+
const outputDirToSrc = path.join(appDirectory, distPath, outputPath, staticPath);
|
|
81
94
|
copyAssets({
|
|
82
95
|
targetDir: srcDir,
|
|
83
96
|
outputDir: outputDirToSrc
|
|
84
97
|
});
|
|
85
|
-
|
|
86
|
-
targetDir: styleDir,
|
|
87
|
-
outputDir: outputDirToStyle
|
|
88
|
-
});
|
|
89
|
-
copyUtils.copyTask({
|
|
98
|
+
await copyUtils.copyTask({
|
|
90
99
|
modernConfig,
|
|
91
100
|
appContext
|
|
92
101
|
});
|
|
93
102
|
|
|
94
103
|
if (config.watch) {
|
|
95
|
-
watchAssets({
|
|
104
|
+
watchAssets(api, {
|
|
96
105
|
targetDir: srcDir,
|
|
97
106
|
outputDir: outputDirToSrc
|
|
98
107
|
});
|
|
99
|
-
watchAssets({
|
|
100
|
-
targetDir: styleDir,
|
|
101
|
-
outputDir: outputDirToStyle
|
|
102
|
-
});
|
|
103
108
|
}
|
|
104
109
|
};
|
|
105
110
|
|
|
106
|
-
|
|
107
|
-
let options;
|
|
108
|
-
|
|
109
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
110
|
-
({
|
|
111
|
-
options
|
|
112
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const {
|
|
116
|
-
resolved: modernConfig,
|
|
117
|
-
appContext
|
|
118
|
-
} = await core.cli.init([], options);
|
|
119
|
-
|
|
120
|
-
(() => {
|
|
121
|
-
try {
|
|
122
|
-
taskMain({
|
|
123
|
-
modernConfig,
|
|
124
|
-
appContext
|
|
125
|
-
});
|
|
126
|
-
} catch (e) {
|
|
127
|
-
console.error(e.message);
|
|
128
|
-
}
|
|
129
|
-
})();
|
|
130
|
-
})();
|
|
111
|
+
exports.copyStaticAssets = copyStaticAssets;
|