@rws-framework/client 2.10.8 → 2.10.9
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/_tools.js +23 -18
- package/cfg/build_steps/webpack/_actions.js +86 -0
- package/cfg/build_steps/webpack/_aliases.js +5 -0
- package/cfg/build_steps/webpack/_build_config.js +77 -0
- package/cfg/build_steps/webpack/_cache.js +99 -0
- package/cfg/build_steps/webpack/_component_handling.js +61 -0
- package/cfg/build_steps/webpack/_dev_servers.js +15 -0
- package/cfg/build_steps/webpack/_env_defines.js +19 -0
- package/cfg/build_steps/webpack/_loaders.js +211 -37
- package/cfg/build_steps/webpack/_plugins.js +100 -0
- package/cfg/build_steps/webpack/_timing.js +53 -0
- package/cfg/build_steps/webpack/_webpack_config.js +59 -0
- package/cfg/tsconfigSetup.js +1 -2
- package/package.json +3 -2
- package/rws.webpack.config.js +109 -240
- package/src/services/UtilsService.ts +1 -31
- package/webpack/loaders/rws_fast_scss_loader.js +3 -0
- package/webpack/loaders/rws_fast_ts_loader.js +43 -101
- package/webpack/rws_scss_plugin.js +6 -3
- package/webpack/rws_webpack_plugin.js +138 -0
- package/webpack/scss/_compiler.js +1 -2
- package/webpack/scss/_import.js +4 -2
- package/webpack/rws_after_plugin.js +0 -104
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const rwsAfterCopy = require('./after/copy');
|
|
2
|
+
const rwsAfterSW = require('./after/sw');
|
|
3
|
+
const deepmerge = require('deepmerge');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const _DEFAULT_CONFIG = { actions: [], executionDir: process.cwd(), packageDir: process.cwd(), dev: false, devDebug: null }
|
|
7
|
+
|
|
8
|
+
const _DEFAULT_ACTION = {
|
|
9
|
+
type: 'copy',
|
|
10
|
+
actionHandler: {
|
|
11
|
+
'targetDir': [
|
|
12
|
+
'filePath0',
|
|
13
|
+
'filePath1'
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
event: 'done'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class RWSWebpackPlugin {
|
|
20
|
+
config = _DEFAULT_CONFIG;
|
|
21
|
+
_allowedActionTypes = ['copy', 'custom', 'service_worker'];
|
|
22
|
+
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
this.config = deepmerge(this.config, config);
|
|
25
|
+
this.customOptions = {
|
|
26
|
+
devDebug: this.config.devDebug
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
apply(compiler) {
|
|
31
|
+
const actionsEvents = this.config.actions.map(item => item.event ? item.event : 'done');
|
|
32
|
+
const errorActionsEvents = this.config.error_actions.map(item => item.event ? item.event : null).filter(item => !!item);
|
|
33
|
+
|
|
34
|
+
compiler.hooks.compilation.tap('RWSWebpackPlugin', (compilation) => {
|
|
35
|
+
compilation['customOptions'] = this.customOptions;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
39
|
+
compiler.hooks[eventName].tapPromise('RWSWebpackPlugin', async (buildInfo) => {
|
|
40
|
+
const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
41
|
+
return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return await Promise.all(proms);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!this.config.dev) {
|
|
49
|
+
compiler.hooks.emit.tapAsync('RWSWebpackPlugin', (compilation, callback) => {
|
|
50
|
+
Object.keys(compilation.assets).forEach((filename) => {
|
|
51
|
+
|
|
52
|
+
if (filename.endsWith('.js')) {
|
|
53
|
+
const asset = compilation.assets[filename];
|
|
54
|
+
let source = asset.source();
|
|
55
|
+
|
|
56
|
+
if ((source.indexOf('css`') > -1 || source.indexOf('html`') > -1)) {
|
|
57
|
+
const updatedSource = source.replace(/\n/g, '');
|
|
58
|
+
|
|
59
|
+
// Update the asset with the new content
|
|
60
|
+
compilation.assets[filename] = {
|
|
61
|
+
source: () => updatedSource,
|
|
62
|
+
size: () => updatedSource.length
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
callback();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// compiler.hooks.done.tap('RWSWebpackPlugin', (stats) => {
|
|
73
|
+
// // Check if there were any errors
|
|
74
|
+
// if (stats.hasErrors()) {
|
|
75
|
+
// console.error('Build failed with errors:');
|
|
76
|
+
|
|
77
|
+
// // Log the errors
|
|
78
|
+
// const info = stats.toJson();
|
|
79
|
+
// console.error(info.errors);
|
|
80
|
+
|
|
81
|
+
// Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
82
|
+
// compiler.hooks[eventName].tapPromise('RWSWebpackPlugin', async (buildInfo) => {
|
|
83
|
+
// const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
84
|
+
// return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
85
|
+
// });
|
|
86
|
+
|
|
87
|
+
// return await Promise.all(proms);
|
|
88
|
+
// });
|
|
89
|
+
// });
|
|
90
|
+
|
|
91
|
+
// // Optionally exit the process with a non-zero status
|
|
92
|
+
// process.exit(1);
|
|
93
|
+
// } else {
|
|
94
|
+
// console.log('Build completed successfully.');
|
|
95
|
+
// }
|
|
96
|
+
// });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async _runActionType(actionType, action) {
|
|
100
|
+
if (!this._allowedActionTypes.includes(actionType)) {
|
|
101
|
+
throw new Error(`[RWSAfter webpack plugin] Action type ${actionType} is not allowed`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
switch (actionType) {
|
|
105
|
+
case 'copy': {
|
|
106
|
+
const copyFiles = typeof action === 'function' ? await action() : action;
|
|
107
|
+
|
|
108
|
+
await rwsAfterCopy(copyFiles, this.config);
|
|
109
|
+
return;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//@TODO
|
|
113
|
+
case 'service_worker': {
|
|
114
|
+
|
|
115
|
+
const serviceWorkerPath = typeof action === 'function' ? await action() : action;
|
|
116
|
+
await rwsAfterSW(serviceWorkerPath);
|
|
117
|
+
return;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
case 'custom': {
|
|
121
|
+
|
|
122
|
+
if (typeof action !== 'function') {
|
|
123
|
+
console.error('Custom RWS action must be a function.')
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
await action();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
console.warn('RWSWebpackPlugin::_runActionType could not act upon input. Please resolve.');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = RWSWebpackPlugin;
|
|
@@ -9,7 +9,7 @@ let _scss_fonts = null;
|
|
|
9
9
|
const _scss_import_builder = require('./_import');
|
|
10
10
|
let _scss_import = null;
|
|
11
11
|
|
|
12
|
-
function compileScssCode(scssCode, fileRootDir, createFile = false, filePath = null, minify = false) {
|
|
12
|
+
function compileScssCode(scssCode, fileRootDir, createFile = false, filePath = null, minify = false) {
|
|
13
13
|
_scss_fonts = _scss_fonts_builder(this);
|
|
14
14
|
_scss_import = _scss_import_builder(this);
|
|
15
15
|
|
|
@@ -41,7 +41,6 @@ function compileScssCode(scssCode, fileRootDir, createFile = false, filePath = n
|
|
|
41
41
|
let compiledCode = result.css.toString();
|
|
42
42
|
compiledCode = _scss_fonts.replaceFontUrlWithBase64(compiledCode);
|
|
43
43
|
compiledCode = replaceEmojisWithQuestionMark(compiledCode, fileRootDir);
|
|
44
|
-
|
|
45
44
|
return { code: compiledCode, dependencies};
|
|
46
45
|
} catch (err) {
|
|
47
46
|
console.error('SASS Error in', fileRootDir);
|
package/webpack/scss/_import.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { rwsPath } = require('@rws-framework/console');
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
const _scss_fs_builder = require('./_fs');
|
|
4
4
|
let _scss_fs = null;
|
|
5
5
|
const fs = require('fs');
|
|
@@ -7,6 +7,8 @@ const path = require('path');
|
|
|
7
7
|
const CSS_IMPORT_REGEX = /^(?!.*\/\/)(?!.*\/\*).*@import\s+['"]((?![^'"]*:[^'"]*).+?)['"];?/gm;
|
|
8
8
|
const SCSS_USE_REGEX = /^(?!.*\/\/)(?!.*\/\*).*@use\s+['"]?([^'"\s]+)['"]?;?/gm;
|
|
9
9
|
|
|
10
|
+
const WORKSPACE = rwsPath.findRootWorkspacePath(process.cwd());
|
|
11
|
+
|
|
10
12
|
function processImportPath(importPath, fileRootDir = null, noext = false) {
|
|
11
13
|
_scss_fs = _scss_fs_builder(this);
|
|
12
14
|
|
|
@@ -123,7 +125,7 @@ function detectImports(code) {
|
|
|
123
125
|
|
|
124
126
|
function replaceWithNodeModules(input, fileDir = null, absolute = false, token = '~') {
|
|
125
127
|
_scss_fs = _scss_fs_builder(this);
|
|
126
|
-
return input.replace(token, absolute ? `${path.resolve(
|
|
128
|
+
return input.replace(token, absolute ? `${path.resolve(WORKSPACE, 'node_modules')}/` : this.node_modules_dir(fileDir ? fileDir : process.cwd()));
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
function processImports(imports, fileRootDir, importStorage = {}, sub = false) {
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const rwsAfterCopy = require('./after/copy');
|
|
2
|
-
const rwsAfterSW = require('./after/sw');
|
|
3
|
-
const deepmerge = require('deepmerge');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const _DEFAULT_CONFIG = {actions: [], executionDir: process.cwd(), packageDir: process.cwd(), dev: false}
|
|
7
|
-
|
|
8
|
-
const _DEFAULT_ACTION = {
|
|
9
|
-
type: 'copy',
|
|
10
|
-
actionHandler: {
|
|
11
|
-
'targetDir': [
|
|
12
|
-
'filePath0',
|
|
13
|
-
'filePath1'
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
event: 'done'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class RWSAfterPlugin {
|
|
20
|
-
config = _DEFAULT_CONFIG;
|
|
21
|
-
_allowedActionTypes = ['copy', 'custom', 'service_worker'];
|
|
22
|
-
|
|
23
|
-
constructor(config = {}){
|
|
24
|
-
this.config = deepmerge(this.config, config);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
apply(compiler) {
|
|
28
|
-
const actionsEvents = this.config.actions.map(item => item.event ? item.event : 'done');
|
|
29
|
-
|
|
30
|
-
Array.from(new Set(actionsEvents)).forEach((eventName) => {
|
|
31
|
-
compiler.hooks[eventName].tapPromise('RWSAfterPlugin', async (buildInfo) => {
|
|
32
|
-
const proms = this.config.actions.filter(item => item.event === _DEFAULT_ACTION.event || !item.event).map(async (rwsAfterAction) => {
|
|
33
|
-
return await this._runActionType(rwsAfterAction.type, rwsAfterAction.actionHandler);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return await Promise.all(proms);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if(!this.config.dev){
|
|
41
|
-
compiler.hooks.emit.tapAsync('RWSAfterPlugin', (compilation, callback) => {
|
|
42
|
-
Object.keys(compilation.assets).forEach((filename) => {
|
|
43
|
-
|
|
44
|
-
if (filename.endsWith('.js')) {
|
|
45
|
-
const asset = compilation.assets[filename];
|
|
46
|
-
let source = asset.source();
|
|
47
|
-
|
|
48
|
-
if((source.indexOf('css`') > -1 || source.indexOf('html`') > -1)){
|
|
49
|
-
const updatedSource = source.replace(/\n/g, '');
|
|
50
|
-
|
|
51
|
-
// Update the asset with the new content
|
|
52
|
-
compilation.assets[filename] = {
|
|
53
|
-
source: () => updatedSource,
|
|
54
|
-
size: () => updatedSource.length
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
callback();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async _runActionType(actionType, action){
|
|
66
|
-
if(!this._allowedActionTypes.includes(actionType)){
|
|
67
|
-
throw new Error(`[RWSAfter webpack plugin] Action type ${actionType} is not allowed`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
switch (actionType){
|
|
71
|
-
case 'copy': {
|
|
72
|
-
const copyFiles = typeof action === 'function' ? await action() : action;
|
|
73
|
-
|
|
74
|
-
await rwsAfterCopy(copyFiles, this.config);
|
|
75
|
-
return;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
//@TODO
|
|
79
|
-
case 'service_worker': {
|
|
80
|
-
|
|
81
|
-
const serviceWorkerPath = typeof action === 'function' ? await action() : action;
|
|
82
|
-
await rwsAfterSW(serviceWorkerPath);
|
|
83
|
-
return;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
case 'custom': {
|
|
87
|
-
|
|
88
|
-
if(typeof action !== 'function'){
|
|
89
|
-
console.error('Custom RWS action must be a function.')
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
await action();
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
default:
|
|
98
|
-
console.warn('RWSAfterPlugin::_runActionType could not act upon input. Please resolve.');
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = RWSAfterPlugin;
|