@moneko/core 3.0.0-beta.30 → 3.0.0-beta.32
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/lib/common.js +175 -2
- package/lib/coverage.js +30 -1
- package/lib/done.js +12 -1
- package/lib/envFlags.js +48 -1
- package/lib/esm.js +7 -1
- package/lib/has-pkg.js +14 -1
- package/lib/html-add-entry-attr.js +22 -1
- package/lib/html-plugin-option.js +41 -1
- package/lib/index.js +4 -1
- package/lib/minify.js +46 -1
- package/lib/modifyVars.js +11 -1
- package/lib/module-federation.js +46 -1
- package/lib/module.config.js +184 -1
- package/lib/process-env.js +63 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.d.ts +1 -0
- package/lib/routes.js +171 -0
- package/lib/seo.js +57 -1
- package/lib/swcrc.js +107 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +64 -1
- package/lib/webpack.common.d.ts +1 -0
- package/lib/webpack.common.js +218 -1
- package/lib/webpack.dev.js +97 -3
- package/lib/webpack.prod.js +64 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +3 -3
package/lib/utils.js
CHANGED
|
@@ -1 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
2
|
+
import { networkInterfaces } from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { transformFileSync } from '@swc/core';
|
|
5
|
+
import { cacheDir } from './process-env.js';
|
|
6
|
+
import resolverSync from './resolver-sync.js';
|
|
7
|
+
const swcOption = {
|
|
8
|
+
inputSourceMap: false,
|
|
9
|
+
sourceMaps: false,
|
|
10
|
+
module: {
|
|
11
|
+
type: 'es6'
|
|
12
|
+
},
|
|
13
|
+
jsc: {
|
|
14
|
+
parser: {
|
|
15
|
+
syntax: 'typescript'
|
|
16
|
+
},
|
|
17
|
+
loose: false
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export function tfc(filepath) {
|
|
21
|
+
return transformFileSync(filepath, swcOption).code || '{}';
|
|
22
|
+
}
|
|
23
|
+
export function readConf(src, name) {
|
|
24
|
+
const cacheFile = path.join(cacheDir, `${name}.mjs`);
|
|
25
|
+
writeFileSync(cacheFile, tfc(src), 'utf-8');
|
|
26
|
+
return import(cacheFile);
|
|
27
|
+
}
|
|
28
|
+
export function toUpperCaseString(string) {
|
|
29
|
+
return string?.replace(/\b\w/g, (th)=>th.toUpperCase()).replace(/\./g, ' ');
|
|
30
|
+
}
|
|
31
|
+
export function getIPAdress() {
|
|
32
|
+
const interfaces = networkInterfaces();
|
|
33
|
+
for(const devName in interfaces){
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(interfaces, devName)) {
|
|
35
|
+
const iface = interfaces[devName];
|
|
36
|
+
for(let i = 0; i < iface.length; i++){
|
|
37
|
+
const alias = iface[i];
|
|
38
|
+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith('169.254') && !alias.internal) {
|
|
39
|
+
return alias.address;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function resolveProgramPath(src) {
|
|
46
|
+
return path.resolve(process.cwd(), './' + src);
|
|
47
|
+
}
|
|
48
|
+
export const resolveNodeModulesPath = (src)=>{
|
|
49
|
+
return resolveProgramPath(`node_modules/${src}`);
|
|
50
|
+
};
|
|
51
|
+
export const resolve = (url)=>resolverSync.resolveSync({}, process.cwd(), url) || url;
|
|
52
|
+
const funcTag = '[object Function]';
|
|
53
|
+
const asyncTag = '[object AsyncFunction]';
|
|
54
|
+
const genTag = '[object GeneratorFunction]';
|
|
55
|
+
const proxyTag = '[object Proxy]';
|
|
56
|
+
export function isObject(target) {
|
|
57
|
+
const type = typeof target;
|
|
58
|
+
return target !== null && (type == 'object' || type == 'function');
|
|
59
|
+
}
|
|
60
|
+
export function isFunction(target) {
|
|
61
|
+
if (!isObject(target)) return false;
|
|
62
|
+
const tagType = Object.prototype.toString.call(target);
|
|
63
|
+
return tagType == funcTag || tagType == asyncTag || tagType == genTag || tagType == proxyTag;
|
|
64
|
+
}
|
package/lib/webpack.common.d.ts
CHANGED
package/lib/webpack.common.js
CHANGED
|
@@ -1 +1,218 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin';
|
|
3
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
4
|
+
import webpack from 'webpack';
|
|
5
|
+
import WebpackBar from 'webpackbar';
|
|
6
|
+
import { CONFIG, ENTRYPATH, PUBLICPATH } from './common.js';
|
|
7
|
+
import DoneWebpackPlugin from './done.js';
|
|
8
|
+
import envFlags from './envFlags.js';
|
|
9
|
+
import AddEntryAttributeWebpackPlugin from './html-add-entry-attr.js';
|
|
10
|
+
import htmlPluginOption from './html-plugin-option.js';
|
|
11
|
+
import { moduleFederation } from './module-federation.js';
|
|
12
|
+
import moduleConfig from './module.config.js';
|
|
13
|
+
import { APPTYPE, DEV, hasEslintConfig, hasStylelintConfig, PACKAGENAME, PROGRAMPATH, FRAMEWORK } from './process-env.js';
|
|
14
|
+
import './routes.js';
|
|
15
|
+
import { seo } from './seo.js';
|
|
16
|
+
import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
17
|
+
const eslintrc = [
|
|
18
|
+
'.eslintrc.js',
|
|
19
|
+
'.eslintrc.json',
|
|
20
|
+
'.eslintrc.yaml',
|
|
21
|
+
'.eslintrc.json'
|
|
22
|
+
];
|
|
23
|
+
const stylelintrc = [
|
|
24
|
+
'.stylelintrc',
|
|
25
|
+
'.stylelintrc.json',
|
|
26
|
+
'.stylelintrc.yaml',
|
|
27
|
+
'.stylelintrc.yml',
|
|
28
|
+
'.stylelintrc.js',
|
|
29
|
+
'stylelint.config.js',
|
|
30
|
+
'stylelint.config.cjs'
|
|
31
|
+
];
|
|
32
|
+
const rootFiles = fs.readdirSync(PROGRAMPATH);
|
|
33
|
+
let hasEslint = false, hasStylelint = false;
|
|
34
|
+
for(let i = 0, len = rootFiles.length; i < len; i++){
|
|
35
|
+
if (stylelintrc.includes(rootFiles[i])) {
|
|
36
|
+
hasStylelint = true;
|
|
37
|
+
}
|
|
38
|
+
if (eslintrc.includes(rootFiles[i])) {
|
|
39
|
+
hasEslint = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!hasEslint) {
|
|
43
|
+
hasEslint = hasEslintConfig;
|
|
44
|
+
}
|
|
45
|
+
if (!hasStylelint) {
|
|
46
|
+
hasStylelint = hasStylelintConfig;
|
|
47
|
+
}
|
|
48
|
+
const StylelintPlugin = hasStylelint ? (await import('stylelint-webpack-plugin')).default : null;
|
|
49
|
+
const ESLintPlugin = hasEslint ? (await import('eslint-webpack-plugin')).default : null;
|
|
50
|
+
const alias = {
|
|
51
|
+
'@': resolveProgramPath('src')
|
|
52
|
+
};
|
|
53
|
+
Object.assign(alias, CONFIG.alias);
|
|
54
|
+
if (APPTYPE === 'library') {
|
|
55
|
+
Object.assign(alias, {
|
|
56
|
+
'@': resolveProgramPath('site'),
|
|
57
|
+
'@pkg': resolveProgramPath('components'),
|
|
58
|
+
[PACKAGENAME]: resolveProgramPath('components')
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const assetHtmlOption = CONFIG.assetHtml.map((item)=>{
|
|
62
|
+
return {
|
|
63
|
+
publicPath: '',
|
|
64
|
+
...item
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
export const outputConfig = {
|
|
68
|
+
path: resolveProgramPath(APPTYPE === 'library' ? 'docs' : 'dist'),
|
|
69
|
+
filename: 'js/[name].bundle.js',
|
|
70
|
+
chunkFilename: 'js/[name].chunk.js',
|
|
71
|
+
assetModuleFilename: `assets/[name].[hash][ext]`,
|
|
72
|
+
library: PACKAGENAME,
|
|
73
|
+
libraryTarget: 'window',
|
|
74
|
+
globalObject: 'window',
|
|
75
|
+
chunkLoadingGlobal: `webpackJsonp_${PACKAGENAME}`,
|
|
76
|
+
pathinfo: false,
|
|
77
|
+
clean: true,
|
|
78
|
+
publicPath: PUBLICPATH
|
|
79
|
+
};
|
|
80
|
+
let mainEntry = resolveNodeModulesPath(`@moneko/${FRAMEWORK}/lib/packages/${ENTRYPATH[APPTYPE]}/index.js`);
|
|
81
|
+
if (APPTYPE === 'single-component') {
|
|
82
|
+
Object.assign(alias, {
|
|
83
|
+
[PACKAGENAME]: resolveProgramPath('umd')
|
|
84
|
+
});
|
|
85
|
+
mainEntry = resolveProgramPath(DEV ? 'example/index.ts' : 'src/index.ts');
|
|
86
|
+
outputConfig.path = resolveProgramPath(DEV ? 'dist' : 'umd');
|
|
87
|
+
outputConfig.filename = 'index.js';
|
|
88
|
+
outputConfig.library = PACKAGENAME;
|
|
89
|
+
outputConfig.libraryTarget = 'umd';
|
|
90
|
+
outputConfig.libraryExport = 'default';
|
|
91
|
+
}
|
|
92
|
+
let entryMap = {
|
|
93
|
+
main: mainEntry
|
|
94
|
+
};
|
|
95
|
+
if (CONFIG.entry) {
|
|
96
|
+
if (typeof CONFIG.entry === 'string') {
|
|
97
|
+
entryMap = CONFIG.entry;
|
|
98
|
+
} else if (Object.keys(CONFIG.entry)) {
|
|
99
|
+
Object.assign(entryMap, CONFIG.entry);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (CONFIG.output) {
|
|
103
|
+
if (typeof CONFIG.output === 'string') {
|
|
104
|
+
outputConfig.path = CONFIG.output;
|
|
105
|
+
} else if (Object.keys(CONFIG.output)) {
|
|
106
|
+
Object.assign(outputConfig, CONFIG.output);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const dirDeep = CONFIG.routeBaseName.split('/').filter(Boolean).length;
|
|
110
|
+
const page404 = Array(dirDeep).fill('..').join('/') + (dirDeep ? '/' : '') + '404.html';
|
|
111
|
+
const { pathSegmentsToKeep =dirDeep , path =page404 } = CONFIG.fixBrowserRouter || {};
|
|
112
|
+
const config = {
|
|
113
|
+
entry: entryMap,
|
|
114
|
+
stats: 'errors-only',
|
|
115
|
+
infrastructureLogging: {
|
|
116
|
+
level: 'none'
|
|
117
|
+
},
|
|
118
|
+
target: 'web',
|
|
119
|
+
plugins: [
|
|
120
|
+
new webpack.AutomaticPrefetchPlugin(),
|
|
121
|
+
...moduleFederation,
|
|
122
|
+
ESLintPlugin && new ESLintPlugin({
|
|
123
|
+
fix: true,
|
|
124
|
+
threads: true,
|
|
125
|
+
extensions: [
|
|
126
|
+
'js',
|
|
127
|
+
'md',
|
|
128
|
+
'mdx',
|
|
129
|
+
'cjs',
|
|
130
|
+
'ejs',
|
|
131
|
+
'mjs',
|
|
132
|
+
'jsx',
|
|
133
|
+
'ts',
|
|
134
|
+
'tsx',
|
|
135
|
+
'json',
|
|
136
|
+
'html',
|
|
137
|
+
'coffee',
|
|
138
|
+
'vue'
|
|
139
|
+
]
|
|
140
|
+
}),
|
|
141
|
+
StylelintPlugin && new StylelintPlugin({
|
|
142
|
+
fix: true,
|
|
143
|
+
threads: true,
|
|
144
|
+
extensions: [
|
|
145
|
+
'css',
|
|
146
|
+
'scss',
|
|
147
|
+
'sass',
|
|
148
|
+
'less',
|
|
149
|
+
'ts',
|
|
150
|
+
'tsx',
|
|
151
|
+
'js',
|
|
152
|
+
'jsx'
|
|
153
|
+
],
|
|
154
|
+
exclude: [
|
|
155
|
+
'node_modules/',
|
|
156
|
+
'es/',
|
|
157
|
+
'lib/',
|
|
158
|
+
'docs/',
|
|
159
|
+
'coverage/',
|
|
160
|
+
'dist/'
|
|
161
|
+
]
|
|
162
|
+
}),
|
|
163
|
+
new HtmlWebpackPlugin(htmlPluginOption),
|
|
164
|
+
CONFIG.fixBrowserRouter && new HtmlWebpackPlugin({
|
|
165
|
+
filename: path,
|
|
166
|
+
inject: false,
|
|
167
|
+
templateContent: ()=>`<html html><head><title>${htmlPluginOption.title}</title><script>var pathSegmentsToKeep = ${pathSegmentsToKeep || dirDeep};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`
|
|
168
|
+
}),
|
|
169
|
+
new AddAssetHtmlPlugin(assetHtmlOption),
|
|
170
|
+
APPTYPE === 'single-spa' && new AddEntryAttributeWebpackPlugin((src)=>{
|
|
171
|
+
return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
|
|
172
|
+
}),
|
|
173
|
+
new webpack.DefinePlugin(envFlags),
|
|
174
|
+
new webpack.WatchIgnorePlugin({
|
|
175
|
+
paths: [
|
|
176
|
+
/\.d\.ts$/
|
|
177
|
+
]
|
|
178
|
+
}),
|
|
179
|
+
CONFIG.sourceMap && new webpack.SourceMapDevToolPlugin(CONFIG.sourceMap),
|
|
180
|
+
new WebpackBar({
|
|
181
|
+
name: '编译中',
|
|
182
|
+
color: '#6f42c1'
|
|
183
|
+
}),
|
|
184
|
+
new DoneWebpackPlugin({
|
|
185
|
+
done: ()=>{
|
|
186
|
+
if (!DEV && CONFIG.seo) {
|
|
187
|
+
seo();
|
|
188
|
+
}
|
|
189
|
+
CONFIG.done?.();
|
|
190
|
+
}
|
|
191
|
+
}),
|
|
192
|
+
...CONFIG.plugins
|
|
193
|
+
].filter(Boolean),
|
|
194
|
+
experiments: {
|
|
195
|
+
topLevelAwait: true,
|
|
196
|
+
syncWebAssembly: true,
|
|
197
|
+
asyncWebAssembly: true
|
|
198
|
+
},
|
|
199
|
+
resolve: {
|
|
200
|
+
extensions: [
|
|
201
|
+
'.tsx',
|
|
202
|
+
'.ts',
|
|
203
|
+
'.js',
|
|
204
|
+
'.jsx'
|
|
205
|
+
],
|
|
206
|
+
alias: alias,
|
|
207
|
+
fallback: {
|
|
208
|
+
path: false,
|
|
209
|
+
fs: false,
|
|
210
|
+
crypto: false,
|
|
211
|
+
assert: false
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
module: moduleConfig,
|
|
215
|
+
externals: CONFIG.externals,
|
|
216
|
+
output: outputConfig
|
|
217
|
+
};
|
|
218
|
+
export default config;
|
package/lib/webpack.dev.js
CHANGED
|
@@ -1,4 +1,98 @@
|
|
|
1
|
-
import
|
|
1
|
+
import FriendlyErrorsWebpackPlugin from '@soda/friendly-errors-webpack-plugin';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { getPort } from 'portfinder';
|
|
4
|
+
import webpack from 'webpack';
|
|
5
|
+
import { merge } from 'webpack-merge';
|
|
6
|
+
import { CONFIG } from './common.js';
|
|
7
|
+
import { hasPkg } from './has-pkg.js';
|
|
8
|
+
import { FRAMEWORK } from './process-env.js';
|
|
9
|
+
import { getIPAdress, isFunction, resolveProgramPath } from './utils.js';
|
|
10
|
+
import common from './webpack.common.js';
|
|
11
|
+
const hasMockMiddlewares = hasPkg('@moneko/mock');
|
|
12
|
+
const mockMiddlewares = hasMockMiddlewares && await import('@moneko/mock');
|
|
13
|
+
const ReactRefresh = FRAMEWORK === 'react' && (await import('@pmmmwh/react-refresh-webpack-plugin')).default;
|
|
14
|
+
let cacheConfig = false;
|
|
15
|
+
if (CONFIG.cacheDirectory) {
|
|
16
|
+
cacheConfig = {
|
|
17
|
+
type: 'filesystem',
|
|
18
|
+
allowCollectingMemory: true,
|
|
19
|
+
cacheDirectory: CONFIG.cacheDirectory
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const devtool = CONFIG.devtool === false || CONFIG.devtool ? CONFIG.devtool : 'eval-cheap-module-source-map';
|
|
23
|
+
const webpackConfig = new Promise((resolve)=>{
|
|
24
|
+
getPort({
|
|
25
|
+
port: CONFIG.devServer.port,
|
|
26
|
+
stopPort: 9999
|
|
27
|
+
}, (_err, port)=>{
|
|
28
|
+
const notes = [];
|
|
29
|
+
if (CONFIG.devServer.port !== port) {
|
|
30
|
+
notes.push(`Port ${chalk.yellow(CONFIG.devServer.port)} is in use, trying ${chalk.green(port)} instead`);
|
|
31
|
+
}
|
|
32
|
+
CONFIG.devServer.port = port;
|
|
33
|
+
const initRouteBase = CONFIG.routeBaseName === '/';
|
|
34
|
+
const protocol = CONFIG.devServer.https ? 'https:' : 'http:';
|
|
35
|
+
const routeBase = initRouteBase ? '' : CONFIG.routeBaseName;
|
|
36
|
+
const conf = merge(common, {
|
|
37
|
+
devtool: devtool,
|
|
38
|
+
mode: 'development',
|
|
39
|
+
cache: cacheConfig,
|
|
40
|
+
devServer: {
|
|
41
|
+
headers: {
|
|
42
|
+
'Access-Control-Allow-Origin': '*'
|
|
43
|
+
},
|
|
44
|
+
compress: CONFIG.devServer.compress,
|
|
45
|
+
host: '0.0.0.0',
|
|
46
|
+
port: port,
|
|
47
|
+
historyApiFallback: initRouteBase || {
|
|
48
|
+
index: routeBase,
|
|
49
|
+
disableDotRule: true
|
|
50
|
+
},
|
|
51
|
+
https: CONFIG.devServer.https,
|
|
52
|
+
proxy: CONFIG.proxy,
|
|
53
|
+
allowedHosts: CONFIG.devServer.allowedHosts,
|
|
54
|
+
client: {
|
|
55
|
+
progress: false,
|
|
56
|
+
logging: 'info',
|
|
57
|
+
overlay: false
|
|
58
|
+
},
|
|
59
|
+
static: {
|
|
60
|
+
watch: {
|
|
61
|
+
ignored: (f)=>{
|
|
62
|
+
return f.endsWith('.d.ts') || /\/node_modules\//.test(f);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
setupMiddlewares: (middlewares, devServer)=>{
|
|
67
|
+
if (!devServer) {
|
|
68
|
+
throw new Error('webpack-dev-server is not defined');
|
|
69
|
+
}
|
|
70
|
+
if (devServer.app && isFunction(mockMiddlewares)) {
|
|
71
|
+
mockMiddlewares(devServer.app, resolveProgramPath('mock/'));
|
|
72
|
+
}
|
|
73
|
+
return middlewares;
|
|
74
|
+
},
|
|
75
|
+
open: false,
|
|
76
|
+
hot: true
|
|
77
|
+
},
|
|
78
|
+
plugins: [
|
|
79
|
+
new webpack.HotModuleReplacementPlugin(),
|
|
80
|
+
ReactRefresh && new ReactRefresh(),
|
|
81
|
+
new FriendlyErrorsWebpackPlugin({
|
|
82
|
+
compilationSuccessInfo: {
|
|
83
|
+
messages: [
|
|
84
|
+
`You application is running here:
|
|
2
85
|
|
|
3
|
-
local: ${
|
|
4
|
-
network: ${
|
|
86
|
+
local: ${chalk.cyan(`${protocol}//${CONFIG.devServer.host}:${port}${routeBase}`)}
|
|
87
|
+
network: ${chalk.cyan(`${protocol}//${getIPAdress()}:${port}${routeBase}`)}`
|
|
88
|
+
],
|
|
89
|
+
notes: notes
|
|
90
|
+
},
|
|
91
|
+
clearConsole: true
|
|
92
|
+
})
|
|
93
|
+
].filter(Boolean)
|
|
94
|
+
});
|
|
95
|
+
resolve(conf);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
export default webpackConfig;
|
package/lib/webpack.prod.js
CHANGED
|
@@ -1 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
2
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
3
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
4
|
+
import webpack from 'webpack';
|
|
5
|
+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
6
|
+
import { merge } from 'webpack-merge';
|
|
7
|
+
import { CONFIG } from './common.js';
|
|
8
|
+
import { getMinifyOption } from './minify.js';
|
|
9
|
+
import common from './webpack.common.js';
|
|
10
|
+
const { cssnanoMinify , swcMinify } = CssMinimizerPlugin;
|
|
11
|
+
const defaultJsMiniify = CONFIG.compiler === 'swc' ? 'swc' : 'terser';
|
|
12
|
+
const defaultCssMiniify = CONFIG.compiler === 'swc' ? 'swc' : 'cssnano';
|
|
13
|
+
const cssMinify = {
|
|
14
|
+
swc: swcMinify,
|
|
15
|
+
cssnano: cssnanoMinify
|
|
16
|
+
};
|
|
17
|
+
const minimizer = [];
|
|
18
|
+
if (CONFIG.minifier) {
|
|
19
|
+
if (CONFIG.minifier.js) {
|
|
20
|
+
minimizer.push(new TerserPlugin(getMinifyOption(CONFIG.minifier.js?.type || defaultJsMiniify, CONFIG.minifier.js?.options)));
|
|
21
|
+
}
|
|
22
|
+
if (CONFIG.minifier.css) {
|
|
23
|
+
minimizer.push(new CssMinimizerPlugin({
|
|
24
|
+
minify: cssMinify[CONFIG.minifier.css?.type || defaultCssMiniify],
|
|
25
|
+
minimizerOptions: CONFIG.minifier.css?.options
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const optimization = {
|
|
30
|
+
splitChunks: CONFIG.splitChunk,
|
|
31
|
+
runtimeChunk: CONFIG.runtimeChunk,
|
|
32
|
+
chunkIds: 'named',
|
|
33
|
+
moduleIds: 'named',
|
|
34
|
+
removeAvailableModules: true,
|
|
35
|
+
removeEmptyChunks: true,
|
|
36
|
+
mergeDuplicateChunks: true,
|
|
37
|
+
minimize: true,
|
|
38
|
+
minimizer: minimizer
|
|
39
|
+
};
|
|
40
|
+
let cacheConfig = false;
|
|
41
|
+
if (CONFIG.cacheDirectory) {
|
|
42
|
+
cacheConfig = {
|
|
43
|
+
type: 'filesystem',
|
|
44
|
+
allowCollectingMemory: true,
|
|
45
|
+
cacheDirectory: CONFIG.cacheDirectory
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export default merge(common, {
|
|
49
|
+
devtool: CONFIG.devtool === false || CONFIG.devtool ? CONFIG.devtool : 'cheap-module-source-map',
|
|
50
|
+
mode: 'production',
|
|
51
|
+
cache: cacheConfig,
|
|
52
|
+
optimization: optimization,
|
|
53
|
+
plugins: [
|
|
54
|
+
new MiniCssExtractPlugin({
|
|
55
|
+
filename: 'style/[name].bundle.css',
|
|
56
|
+
chunkFilename: 'style/[name].chunk.css',
|
|
57
|
+
experimentalUseImportModule: true
|
|
58
|
+
}),
|
|
59
|
+
CONFIG.bundleAnalyzer && new BundleAnalyzerPlugin(CONFIG.bundleAnalyzer),
|
|
60
|
+
CONFIG.splitChunk && new webpack.optimize.MinChunkSizePlugin({
|
|
61
|
+
minChunkSize: 10000
|
|
62
|
+
})
|
|
63
|
+
].filter(Boolean)
|
|
64
|
+
});
|
package/lib/yarn-argv.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const original = JSON.parse(process.env.npm_config_argv || '{}')?.original;
|
|
2
|
+
const yarnArgv = {};
|
|
3
|
+
original?.forEach((o)=>{
|
|
4
|
+
const m = o.split('=');
|
|
5
|
+
Object.assign(yarnArgv, {
|
|
6
|
+
[m[0]]: m[1] || true
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
export default yarnArgv;
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.32",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=true -C jsc.minify.mangle=
|
|
8
|
+
"build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=true -C jsc.minify.mangle=false -C jsc.minify.compress=false -C minify=false -D",
|
|
9
9
|
"prebuild": "rm -rf ./lib && tsc"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [],
|
|
12
12
|
"author": "moneko",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@emotion/css": "11.11.0",
|
|
16
15
|
"@mdx-js/loader": "2.3.0",
|
|
17
16
|
"@soda/friendly-errors-webpack-plugin": "1.8.1",
|
|
18
17
|
"@swc/core": "1.3.56",
|
|
@@ -51,6 +50,7 @@
|
|
|
51
50
|
"@moneko/mock": "^1.0.9",
|
|
52
51
|
"@moneko/postcss": "^1.0.30",
|
|
53
52
|
"@swc/cli": "0.1.62",
|
|
53
|
+
"@types/js-yaml": "^4.0.5",
|
|
54
54
|
"@types/mini-css-extract-plugin": "^2.5.1",
|
|
55
55
|
"@types/shelljs": "^0.8.12",
|
|
56
56
|
"@types/webpack-bundle-analyzer": "^4.6.0",
|