@zohodesk/react-cli 1.1.19-exp.9 → 1.1.20-exp.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +28 -0
- package/bin/cli.js +0 -4
- package/docs/ReactLive.md +5 -1
- package/lib/babel/cmjs-plugins-presets.js +6 -11
- package/lib/babel/es-plugins-presets.js +6 -12
- package/lib/configs/jest.config.js +2 -2
- package/lib/configs/webpack.dev.config.js +0 -4
- package/lib/configs/webpack.prod.config.js +5 -6
- package/lib/loaderUtils/getDevJsLoaders.js +1 -1
- package/lib/loaders/docsLoader.js +2 -2
- package/lib/loaders/enhancedReactLiveConverter.js +151 -0
- package/lib/loaders/workerLoader.js +39 -24
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +59 -1
- package/lib/pluginUtils/getDevPlugins.js +9 -4
- package/lib/pluginUtils/getProdPlugins.js +7 -2
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +111 -0
- package/lib/plugins/EventsHandlingPlugin.js +36 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
- package/lib/schemas/index.js +2 -4
- package/lib/utils/index.js +14 -0
- package/lib/utils/typeCheck.js +10 -0
- package/npm-shrinkwrap.json +19073 -432
- package/package.json +1 -6
package/README.md
CHANGED
@@ -44,6 +44,34 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.1.20-exp.1
|
48
|
+
|
49
|
+
**Changes**
|
50
|
+
|
51
|
+
- Added memory leak fixes for script, links tags
|
52
|
+
|
53
|
+
**Feature**
|
54
|
+
- Custom Script loading strategy support for initial html script tags.
|
55
|
+
|
56
|
+
# 1.1.19-exp.18
|
57
|
+
|
58
|
+
**Changes**
|
59
|
+
|
60
|
+
- To do further build size optimization by utilizing webpack provided config.
|
61
|
+
|
62
|
+
```
|
63
|
+
innerGraph: true,
|
64
|
+
usedExports: true,
|
65
|
+
sideEffects: true
|
66
|
+
```
|
67
|
+
# 1.1.19 (27-5-2024)
|
68
|
+
|
69
|
+
**Feature**
|
70
|
+
|
71
|
+
- enhancedReactLiveConverter.js added and imported in docLoader file
|
72
|
+
|
73
|
+
- stats.json file creation deleted, if `enable_stats` option is false.
|
74
|
+
|
47
75
|
# 1.1.19 (5-2-2024)
|
48
76
|
|
49
77
|
**Feature:-**
|
package/bin/cli.js
CHANGED
@@ -300,8 +300,6 @@ switch (option) {
|
|
300
300
|
'src',
|
301
301
|
'-d',
|
302
302
|
'lib',
|
303
|
-
'--extensions',
|
304
|
-
'.js,.ts,.tsx',
|
305
303
|
`--presets=${require.resolve('../lib/babel/cmjs-plugins-presets.js')}`,
|
306
304
|
'--copy-files'
|
307
305
|
].concat(args),
|
@@ -318,8 +316,6 @@ switch (option) {
|
|
318
316
|
'src',
|
319
317
|
'--out-dir',
|
320
318
|
'es',
|
321
|
-
'--extensions',
|
322
|
-
'.js,.ts,.tsx',
|
323
319
|
`--presets=${require.resolve('../lib/babel/es-plugins-presets.js')}`,
|
324
320
|
'--copy-files'
|
325
321
|
].concat(args),
|
package/docs/ReactLive.md
CHANGED
@@ -11,4 +11,8 @@
|
|
11
11
|
|
12
12
|
# v1.1.2 update:
|
13
13
|
|
14
|
-
* ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
|
14
|
+
* ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
|
15
|
+
|
16
|
+
# v1.1.20 update:
|
17
|
+
|
18
|
+
* enhancedReactLiveConverter.js added and imported in docLoader file
|
@@ -11,25 +11,20 @@ var _babelPresetReactOption = _interopRequireDefault(require("./babel-option-uti
|
|
11
11
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
13
|
|
14
|
-
|
14
|
+
let {
|
15
15
|
module: {
|
16
16
|
mode
|
17
|
-
},
|
18
|
-
babelCustomizationForLibrary: {
|
19
|
-
babelPlugins
|
20
17
|
}
|
21
18
|
} = (0, _utils.getOptions)();
|
22
|
-
|
23
|
-
const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
24
|
-
__DOCS__: false
|
25
|
-
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('@babel/plugin-proposal-optional-chaining'), require.resolve('@babel/plugin-proposal-class-properties')];
|
26
|
-
const plugins = [...babelPlugins, ...defaultPlugins];
|
19
|
+
let isProd = mode.toLowerCase() === 'prod';
|
27
20
|
|
28
21
|
var _default = () => ({
|
29
22
|
presets: [require.resolve('@babel/preset-env'), (0, _babelPresetReactOption.default)({
|
30
23
|
disableES5Transpile: false
|
31
|
-
})
|
32
|
-
plugins:
|
24
|
+
})],
|
25
|
+
plugins: [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
26
|
+
__DOCS__: false
|
27
|
+
} : {}]]
|
33
28
|
});
|
34
29
|
|
35
30
|
exports.default = _default;
|
@@ -11,21 +11,13 @@ var _babelPresetReactOption = _interopRequireDefault(require("./babel-option-uti
|
|
11
11
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
13
|
|
14
|
-
|
14
|
+
let {
|
15
15
|
module: {
|
16
16
|
mode,
|
17
17
|
disableES5Transpile
|
18
|
-
},
|
19
|
-
babelCustomizationForLibrary: {
|
20
|
-
babelPlugins
|
21
18
|
}
|
22
19
|
} = (0, _utils.getOptions)();
|
23
|
-
|
24
|
-
const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
25
|
-
__DOCS__: false
|
26
|
-
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('@babel/plugin-proposal-optional-chaining'), require.resolve('@babel/plugin-proposal-class-properties')];
|
27
|
-
const plugins = [...babelPlugins, ...defaultPlugins];
|
28
|
-
console.log(disableES5Transpile);
|
20
|
+
let isProd = mode.toLowerCase() === 'prod';
|
29
21
|
|
30
22
|
var _default = () => ({
|
31
23
|
presets: [[require.resolve('@babel/preset-env'), disableES5Transpile ? {
|
@@ -39,8 +31,10 @@ var _default = () => ({
|
|
39
31
|
modules: false
|
40
32
|
}], (0, _babelPresetReactOption.default)({
|
41
33
|
disableES5Transpile
|
42
|
-
})
|
43
|
-
plugins:
|
34
|
+
})],
|
35
|
+
plugins: [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
36
|
+
__DOCS__: false
|
37
|
+
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import')]
|
44
38
|
});
|
45
39
|
|
46
40
|
exports.default = _default;
|
@@ -28,7 +28,7 @@ const commonConfig = {
|
|
28
28
|
// },
|
29
29
|
transformIgnorePatterns: ['/node_modules/(?!(@zohodesk)/)'],
|
30
30
|
// transformIgnorePatterns: ['/node_modules.*?.js$'],
|
31
|
-
moduleFileExtensions: ['js'
|
31
|
+
moduleFileExtensions: ['js'],
|
32
32
|
setupFiles: [(0, _fs.existsSync)(appGlobals) && appGlobals, _path.default.resolve(__dirname, '..', 'jest', 'setup.js')].filter(Boolean),
|
33
33
|
globals: {
|
34
34
|
__DEVELOPMENT__: true,
|
@@ -52,7 +52,7 @@ module.exports = (...args) => {
|
|
52
52
|
testPathIgnorePatterns: ['/node_modules/', 'docs'],
|
53
53
|
unmockedModulePathPatterns: ['__tests__', 'node_modules', '.*'],
|
54
54
|
roots: [`<rootDir>/${appFolder}/`],
|
55
|
-
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(jsx|js|json|node
|
55
|
+
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(jsx|js|json|node)$',
|
56
56
|
testResultsProcessor: _path.default.resolve(__dirname, '..', 'jest', 'result.js')
|
57
57
|
});
|
58
58
|
};
|
@@ -102,7 +102,10 @@ module.exports = {
|
|
102
102
|
// exclude: /\/smap/
|
103
103
|
// })
|
104
104
|
// ],
|
105
|
-
moduleIds: 'named'
|
105
|
+
moduleIds: 'named',
|
106
|
+
usedExports: true,
|
107
|
+
// innerGraph: true, // this property present on webpack 5
|
108
|
+
sideEffects: true
|
106
109
|
},
|
107
110
|
stats: {
|
108
111
|
children: false,
|
@@ -131,7 +134,7 @@ module.exports = {
|
|
131
134
|
modules: false
|
132
135
|
}], (0, _babelPresetReactOption.default)({
|
133
136
|
disableES5Transpile
|
134
|
-
})
|
137
|
+
})],
|
135
138
|
plugins: disableES5Transpile ? [removeAttribute ? require.resolve('../utils/removeAttributes') : false, require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('babel-plugin-lodash'), // require.resolve(
|
136
139
|
// '@babel/plugin-proposal-object-rest-spread'
|
137
140
|
// ), REMOVING IT, BECAUSE WE ALREADY SUPPORT SPREAD SYNTAX FROM LIBRARIES.
|
@@ -237,10 +240,6 @@ module.exports = {
|
|
237
240
|
minimize: false
|
238
241
|
}
|
239
242
|
}]
|
240
|
-
}, {
|
241
|
-
test: /\.ts$/,
|
242
|
-
use: 'ts-loader',
|
243
|
-
include: _path.default.join(appPath, folder)
|
244
243
|
}, {
|
245
244
|
test: /\.worker.js$/,
|
246
245
|
use: {
|
@@ -44,7 +44,7 @@ let getDevJsLoaders = options => {
|
|
44
44
|
modules: false
|
45
45
|
}], (0, _babelPresetReactOption.default)({
|
46
46
|
disableES5Transpile
|
47
|
-
})
|
47
|
+
})],
|
48
48
|
plugins: disableES5Transpile ? [require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('babel-plugin-lodash'), // require.resolve('@babel/plugin-proposal-object-rest-spread'),
|
49
49
|
devConsoleExculde ? [require.resolve('babel-plugin-transform-remove-console'), {
|
50
50
|
exclude: ['error', 'log']
|
@@ -6,7 +6,7 @@ var _getOptions = _interopRequireDefault(require("../utils/getOptions.js"));
|
|
6
6
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
8
8
|
|
9
|
-
var
|
9
|
+
var _enhancedReactLiveConverter = require("./enhancedReactLiveConverter.js");
|
10
10
|
|
11
11
|
var _markdownLoader = require("./markdownLoader.js");
|
12
12
|
|
@@ -27,7 +27,7 @@ module.exports = function (source) {
|
|
27
27
|
const src = _fs.default.readFileSync(originalFilePath).toString();
|
28
28
|
|
29
29
|
options.docs.enableMDParser && (source = (0, _markdownLoader.markdownParser)(source));
|
30
|
-
options.docs.enableReactLive && (source = (0,
|
30
|
+
options.docs.enableReactLive && (source = (0, _enhancedReactLiveConverter.enhancedReactLiveConverter)(source, originalFilePath)); //to Enable the ReactLive Converter
|
31
31
|
|
32
32
|
return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
|
33
33
|
};
|
@@ -0,0 +1,151 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.enhancedReactLiveConverter = enhancedReactLiveConverter;
|
7
|
+
|
8
|
+
const parser = require('@babel/parser');
|
9
|
+
|
10
|
+
const traverse = require('@babel/traverse').default;
|
11
|
+
|
12
|
+
const t = require("@babel/types");
|
13
|
+
|
14
|
+
const path = require('path');
|
15
|
+
|
16
|
+
function getFilename(originalFilePath) {
|
17
|
+
const [fileName] = path.basename(originalFilePath).split('.');
|
18
|
+
return fileName;
|
19
|
+
}
|
20
|
+
|
21
|
+
function convertKeyToValue(object = {}) {
|
22
|
+
let keys = Object.keys(object);
|
23
|
+
let values = Object.values(object);
|
24
|
+
return keys.reduce((value, item, i) => {
|
25
|
+
if (item.includes(',')) {
|
26
|
+
item = item.replace(/{|}/g, "");
|
27
|
+
item = '{ ' + item + ' }';
|
28
|
+
}
|
29
|
+
|
30
|
+
value = value + "'" + values[i] + "'" + ": " + item + ",";
|
31
|
+
return value;
|
32
|
+
}, '');
|
33
|
+
}
|
34
|
+
|
35
|
+
function mergeDuplicateValues(obj) {
|
36
|
+
let mergedObj = {};
|
37
|
+
|
38
|
+
for (let key in obj) {
|
39
|
+
if (obj.hasOwnProperty(key)) {
|
40
|
+
let value = obj[key];
|
41
|
+
let existingKey = Object.keys(mergedObj).find(k => mergedObj[k] === value);
|
42
|
+
|
43
|
+
if (existingKey) {
|
44
|
+
mergedObj[existingKey + ' , ' + key] = value;
|
45
|
+
delete mergedObj[existingKey];
|
46
|
+
} else {
|
47
|
+
mergedObj[key] = value;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
return mergedObj;
|
53
|
+
}
|
54
|
+
|
55
|
+
function enhancedReactLiveConverter(source, originalFilePath) {
|
56
|
+
const fileName = getFilename(originalFilePath);
|
57
|
+
|
58
|
+
if (!source) {
|
59
|
+
return '';
|
60
|
+
}
|
61
|
+
|
62
|
+
let docCode = '';
|
63
|
+
const fileContent = source.replace(/[\s\r\n]*$/, '');
|
64
|
+
const ast = parser.parse(fileContent, {
|
65
|
+
sourceType: 'module',
|
66
|
+
plugins: ['jsx', 'classProperties']
|
67
|
+
});
|
68
|
+
|
69
|
+
function createImportStatements(input) {
|
70
|
+
let output = '';
|
71
|
+
|
72
|
+
for (const key in input) {
|
73
|
+
if (input.hasOwnProperty(key) && key !== 'React') {
|
74
|
+
output += `import ${key} from '${input[key]}';\n`;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
return output;
|
79
|
+
}
|
80
|
+
|
81
|
+
const importBlock = {};
|
82
|
+
const printableCode = {};
|
83
|
+
let remainingBlock = ''; // Traverse the AST and find the import and export blocks
|
84
|
+
|
85
|
+
let remainingCode = ast.program.body.filter(node => node.type !== 'ImportDeclaration').filter(node => node.type !== 'ExpressionStatement').map(node => fileContent.substring(node.start, node.end)).join('').trim();
|
86
|
+
traverse(ast, {
|
87
|
+
ImportDeclaration(path) {
|
88
|
+
path.node.specifiers.map(specifier => {
|
89
|
+
if (t.isImportSpecifier(specifier)) {
|
90
|
+
importBlock[`{ ${specifier.local.name} }`] = path.node.source.value;
|
91
|
+
printableCode[`{ ${specifier.local.name} }`] = path.node.source.value;
|
92
|
+
return `{'${specifier.imported.name}': ${specifier.local.name}}`;
|
93
|
+
} else if (t.isImportDefaultSpecifier(specifier)) {
|
94
|
+
importBlock[`${specifier.local.name}`] = `${path.node.source.value}`;
|
95
|
+
printableCode[`${specifier.local.name}`] = `${path.node.source.value} `;
|
96
|
+
return specifier.local.name;
|
97
|
+
}
|
98
|
+
}).join(", ");
|
99
|
+
},
|
100
|
+
|
101
|
+
ExpressionStatement(path) {
|
102
|
+
const expression = path.get('expression');
|
103
|
+
const expressionLeft = expression.get('left');
|
104
|
+
|
105
|
+
if (path.isExpressionStatement() && expression.isAssignmentExpression() && expressionLeft.isMemberExpression()) {
|
106
|
+
const docCheck = expressionLeft.toString();
|
107
|
+
|
108
|
+
if (docCheck === `${fileName}.docs`) {
|
109
|
+
docCode = expression.toString();
|
110
|
+
} else if (docCheck.includes(fileName)) {
|
111
|
+
const startIndex = path.node.start;
|
112
|
+
const endIndex = path.node.end;
|
113
|
+
remainingBlock += fileContent.slice(startIndex, endIndex);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
});
|
119
|
+
remainingCode = remainingCode.replace(/__DOCS__/, true);
|
120
|
+
remainingCode = remainingCode.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
|
121
|
+
remainingBlock = remainingBlock.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
|
122
|
+
const addBractick = `\`
|
123
|
+
${createImportStatements(printableCode)}
|
124
|
+
${remainingCode}
|
125
|
+
|
126
|
+
${remainingBlock}\`
|
127
|
+
`;
|
128
|
+
const template = `
|
129
|
+
|
130
|
+
${createImportStatements(importBlock)}
|
131
|
+
|
132
|
+
import { LiveProviderv3, LiveEditorv3, LiveErrorv3, LivePreviewv3, Wrapper, EditorWrapper , ErrorWrapper, PreviewWrapper } from '@zohodesk-private/react-live/es/index'
|
133
|
+
|
134
|
+
export default class ${fileName} extends React.Component{
|
135
|
+
render(){
|
136
|
+
return(
|
137
|
+
<LiveProviderv3 needToolBox scope={{import: {${convertKeyToValue(mergeDuplicateValues(printableCode))}}}} code={${addBractick}}>
|
138
|
+
<Wrapper>
|
139
|
+
<EditorWrapper><LiveEditorv3 /></EditorWrapper>
|
140
|
+
<PreviewWrapper><LivePreviewv3 /></PreviewWrapper>
|
141
|
+
<LiveErrorv3 needStyle />
|
142
|
+
</Wrapper>
|
143
|
+
</LiveProviderv3>
|
144
|
+
)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
${docCode}
|
149
|
+
`;
|
150
|
+
return template;
|
151
|
+
}
|
@@ -19,32 +19,32 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
19
19
|
/* import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
|
20
20
|
import ExternalsPlugin from 'webpack/lib/ExternalsPlugin'; */
|
21
21
|
const schema = {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
type: 'object',
|
23
|
+
properties: {
|
24
|
+
publicPath: {
|
25
|
+
anyOf: [{
|
26
|
+
type: 'string'
|
27
27
|
}, {
|
28
|
-
|
28
|
+
instanceof: 'Function'
|
29
29
|
}]
|
30
30
|
},
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
filename: {
|
32
|
+
anyOf: [{
|
33
|
+
type: 'string',
|
34
|
+
minLength: 1
|
35
35
|
}, {
|
36
|
-
|
36
|
+
instanceof: 'Function'
|
37
37
|
}]
|
38
38
|
},
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
chunkFilename: {
|
40
|
+
type: 'string',
|
41
|
+
minLength: 1
|
42
42
|
},
|
43
|
-
|
44
|
-
|
43
|
+
esModule: {
|
44
|
+
type: 'boolean'
|
45
45
|
}
|
46
46
|
},
|
47
|
-
|
47
|
+
additionalProperties: false
|
48
48
|
}; // eslint-disable-next-line
|
49
49
|
|
50
50
|
function loader() {}
|
@@ -112,25 +112,40 @@ function pitch(request) {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
function workerCode() {
|
115
|
+
if (this.workerInstance) {
|
116
|
+
return this.workerInstance;
|
117
|
+
}
|
118
|
+
|
115
119
|
let blob;
|
116
120
|
|
117
121
|
try {
|
118
122
|
blob = new Blob([`importScripts('${this.workerUrl}');`], {
|
119
|
-
|
123
|
+
type: 'application/javascript'
|
120
124
|
});
|
121
125
|
} catch (e1) {
|
122
126
|
throw new Error(e1);
|
123
127
|
}
|
124
128
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return
|
129
|
+
const url = window.URL || window.webkitURL;
|
130
|
+
const blobUrl = url.createObjectURL(blob);
|
131
|
+
this.workerInstance = new Worker(blobUrl);
|
132
|
+
return this.workerInstance;
|
129
133
|
}
|
130
134
|
|
131
|
-
return cb(null,
|
135
|
+
return cb(null, `const workerObj ={\n
|
136
|
+
workerInstance: null, \n
|
132
137
|
workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
|
133
138
|
getInstance: ${workerCode} \n
|
134
|
-
}
|
139
|
+
};\n
|
140
|
+
workerObj.getInstance();
|
141
|
+
${options.esModule ? 'export default' : 'module.exports ='} workerObj;
|
142
|
+
`); // return cb(
|
143
|
+
// null,
|
144
|
+
// `${options.esModule ? 'export default' : 'module.exports ='} {\n
|
145
|
+
// workerInstance: null, \n
|
146
|
+
// workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
|
147
|
+
// getInstance: ${workerCode} \n
|
148
|
+
// }`
|
149
|
+
// );
|
135
150
|
});
|
136
151
|
}
|
@@ -13,6 +13,10 @@ var _htmlWebpackInjectAttributesPlugin = _interopRequireDefault(require("html-we
|
|
13
13
|
|
14
14
|
var _common = require("../common");
|
15
15
|
|
16
|
+
var _utils = require("../utils");
|
17
|
+
|
18
|
+
var _CustomScriptLoadingStrategyPlugin = _interopRequireDefault(require("../plugins/CustomScriptLoadingStrategyPlugin"));
|
19
|
+
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
21
|
|
18
22
|
const defaultHTMLMiniFyOption = {
|
@@ -26,6 +30,47 @@ const defaultHTMLMiniFyOption = {
|
|
26
30
|
removeStyleLinkTypeAttributes: true,
|
27
31
|
useShortDoctype: true
|
28
32
|
};
|
33
|
+
const defaultScriptLoadingStrategy = 'defer';
|
34
|
+
const allowedScriptLoadingStrategies = ['blocking', 'defer', 'async', 'module'];
|
35
|
+
|
36
|
+
function isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey) {
|
37
|
+
return allowedScriptLoadingStrategies.includes(scriptLoadingStategey);
|
38
|
+
}
|
39
|
+
|
40
|
+
function getScriptLoadingStrategyForStringType(scriptLoadingStategey) {
|
41
|
+
if (isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey)) {
|
42
|
+
return scriptLoadingStategey;
|
43
|
+
}
|
44
|
+
|
45
|
+
return defaultScriptLoadingStrategy;
|
46
|
+
}
|
47
|
+
|
48
|
+
function getScriptLoadingStrategyForObject(scriptLoadingStategey) {
|
49
|
+
if (Object.keys(scriptLoadingStategey).length === 0) {
|
50
|
+
return defaultScriptLoadingStrategy;
|
51
|
+
}
|
52
|
+
|
53
|
+
const isAllowedScriptLoadingStrategy = Object.keys(scriptLoadingStategey).every(key => isAllowedScriptLoadingStrategyUsed(key));
|
54
|
+
|
55
|
+
if (isAllowedScriptLoadingStrategy) {
|
56
|
+
return Object.assign({}, scriptLoadingStategey);
|
57
|
+
}
|
58
|
+
|
59
|
+
console.warn('un supported script loading strategy used', scriptLoadingStategey);
|
60
|
+
return defaultScriptLoadingStrategy;
|
61
|
+
}
|
62
|
+
|
63
|
+
function getScriptLoadingStrategy(scriptLoadingStategey) {
|
64
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'string') {
|
65
|
+
return getScriptLoadingStrategyForStringType(scriptLoadingStategey);
|
66
|
+
}
|
67
|
+
|
68
|
+
if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'object') {
|
69
|
+
return getScriptLoadingStrategyForObject(scriptLoadingStategey);
|
70
|
+
}
|
71
|
+
|
72
|
+
return 'defer';
|
73
|
+
}
|
29
74
|
|
30
75
|
function configHtmlWebpackPlugins(plugins, {
|
31
76
|
enableChunkHash = false,
|
@@ -33,7 +78,8 @@ function configHtmlWebpackPlugins(plugins, {
|
|
33
78
|
inject,
|
34
79
|
crossorigin,
|
35
80
|
hasEFC,
|
36
|
-
minify: minifyHtmlOptions = false
|
81
|
+
minify: minifyHtmlOptions = false,
|
82
|
+
customScriptLoadingStrategey
|
37
83
|
}) {
|
38
84
|
const optionsHtmlWebpack = {
|
39
85
|
chunksSortMode: 'none',
|
@@ -56,4 +102,16 @@ function configHtmlWebpackPlugins(plugins, {
|
|
56
102
|
crossorigin && plugins.push(new _htmlWebpackInjectAttributesPlugin.default({
|
57
103
|
crossorigin: 'anonymous'
|
58
104
|
}));
|
105
|
+
|
106
|
+
if (customScriptLoadingStrategey) {
|
107
|
+
console.log('script loading stategy', customScriptLoadingStrategey);
|
108
|
+
const currentScriptLoadingStrategy = getScriptLoadingStrategy(customScriptLoadingStrategey);
|
109
|
+
console.log('currentscriptloading strategy', currentScriptLoadingStrategy);
|
110
|
+
|
111
|
+
if ((0, _utils.getTypeOf)(currentScriptLoadingStrategy) === 'object') {
|
112
|
+
plugins.push(new _CustomScriptLoadingStrategyPlugin.default({
|
113
|
+
scriptLoadingStategey: currentScriptLoadingStrategy
|
114
|
+
}));
|
115
|
+
}
|
116
|
+
}
|
59
117
|
}
|
@@ -37,6 +37,8 @@ var _configHtmlWebpackPlugins = require("./configHtmlWebpackPlugins");
|
|
37
37
|
|
38
38
|
var _EfcResourceCleanupPlugin = _interopRequireDefault(require("../plugins/EfcResourceCleanupPlugin"));
|
39
39
|
|
40
|
+
var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
|
41
|
+
|
40
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41
43
|
|
42
44
|
// import { windowsModification } from '../loaderUtils/windowsModification';
|
@@ -60,7 +62,8 @@ const getDevPlugins = (options, publicPath) => {
|
|
60
62
|
mode
|
61
63
|
},
|
62
64
|
htmlTemplate: {
|
63
|
-
inject
|
65
|
+
inject,
|
66
|
+
customScriptLoadingStrategey
|
64
67
|
},
|
65
68
|
crossorigin
|
66
69
|
},
|
@@ -166,7 +169,8 @@ const getDevPlugins = (options, publicPath) => {
|
|
166
169
|
minify: false,
|
167
170
|
inject,
|
168
171
|
crossorigin,
|
169
|
-
hasEFC
|
172
|
+
hasEFC,
|
173
|
+
customScriptLoadingStrategey
|
170
174
|
});
|
171
175
|
|
172
176
|
if (hasEFC) {
|
@@ -217,12 +221,13 @@ const getDevPlugins = (options, publicPath) => {
|
|
217
221
|
exclude: exclude.selectorWeight,
|
218
222
|
patterns
|
219
223
|
}));
|
220
|
-
}
|
224
|
+
}
|
225
|
+
|
226
|
+
pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin()); // if (pluginObject.minifier) {
|
221
227
|
// // console.log('minifier active');
|
222
228
|
// pluginsArr.push(new MinifierPlugin());
|
223
229
|
// }
|
224
230
|
|
225
|
-
|
226
231
|
return pluginsArr.filter(Boolean);
|
227
232
|
};
|
228
233
|
|
@@ -27,6 +27,8 @@ var _VariableConversionCollector = _interopRequireDefault(require("../plugins/Va
|
|
27
27
|
|
28
28
|
var _SelectorPlugin = _interopRequireDefault(require("../plugins/SelectorPlugin"));
|
29
29
|
|
30
|
+
var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
|
31
|
+
|
30
32
|
var _plugins = require("../plugins");
|
31
33
|
|
32
34
|
var _CustomAttributePlugin = require("../plugins/CustomAttributePlugin");
|
@@ -78,7 +80,8 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
78
80
|
} = options.app;
|
79
81
|
const {
|
80
82
|
inject,
|
81
|
-
minify: minifyHtmlOptions
|
83
|
+
minify: minifyHtmlOptions,
|
84
|
+
customScriptLoadingStrategey
|
82
85
|
} = htmlTemplate;
|
83
86
|
const {
|
84
87
|
i18n
|
@@ -176,6 +179,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
176
179
|
folder,
|
177
180
|
inject,
|
178
181
|
minify: minifyHtmlOptions,
|
182
|
+
customScriptLoadingStrategey,
|
179
183
|
crossorigin,
|
180
184
|
hasEFC
|
181
185
|
});
|
@@ -237,7 +241,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
237
241
|
if (bundleAnalyze) {
|
238
242
|
pluginsArr.push(new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
|
239
243
|
analyzerMode: 'static',
|
240
|
-
generateStatsFile:
|
244
|
+
generateStatsFile: false,
|
241
245
|
openAnalyzer: false,
|
242
246
|
statsOptions: enableStats ? null : {
|
243
247
|
source: false,
|
@@ -306,6 +310,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
306
310
|
statsOutputExcludeKeys,
|
307
311
|
statsFileName
|
308
312
|
}));
|
313
|
+
pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin());
|
309
314
|
return pluginsArr;
|
310
315
|
};
|
311
316
|
|