Skip to content

Commit 51129fc

Browse files
Cihan SELİMcihanselim
authored andcommitted
Add: useNodeModulesChunk property to voltran config
1 parent 079b253 commit 51129fc

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

lib/cli.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import arg from 'arg';
22
import fs from 'fs';
33
import path from 'path';
4-
import clc from "cli-color";
4+
import clc from 'cli-color';
55
import { spawn } from 'child_process';
66

77
import normalizeUrl from './os';
@@ -19,10 +19,10 @@ function parseArgumentsIntoOptions(rawArgs) {
1919
'--no-bundle': Boolean,
2020
'--analyze': Boolean,
2121
'--port': Number,
22-
'--ssr': Boolean,
22+
'--ssr': Boolean
2323
},
2424
{
25-
argv: rawArgs.slice(2),
25+
argv: rawArgs.slice(2)
2626
}
2727
);
2828
const argsList = removeUnneccesaryValueInObject({
@@ -32,7 +32,7 @@ function parseArgumentsIntoOptions(rawArgs) {
3232
noBundle: args['--no-bundle'],
3333
analyze: args['--analyze'],
3434
configFile: args['--config'],
35-
ssr: args['--ssr'],
35+
ssr: args['--ssr']
3636
});
3737

3838
return argsList;
@@ -65,35 +65,40 @@ function runDevelopmentMode() {
6565
function runProductionMode(voltranConfigs, onlyBundle) {
6666
const bundle = require('../src/tools/bundle');
6767

68-
bundle()
69-
.then((res) => {
70-
console.log(clc.green('Bundle is completed.\n',`File: ${voltranConfigs.distFolder}/server/server.js`));
68+
bundle().then(res => {
69+
console.log(
70+
clc.green('Bundle is completed.\n', `File: ${voltranConfigs.distFolder}/server/server.js`)
71+
);
7172

72-
if (!onlyBundle) {
73-
serve(voltranConfigs);
74-
}
75-
});
73+
if (!onlyBundle) {
74+
serve(voltranConfigs);
75+
}
76+
});
7677
}
7778

7879
function serve(voltranConfigs) {
7980
console.log(clc.green('Project Serve is starting...'));
8081

81-
const out = spawn('node', [
82-
'-r',
83-
'source-map-support/register',
84-
'--max-http-header-size=20480',
85-
`${voltranConfigs.distFolder}/server/server.js`
86-
], {env: {'NODE_ENV': 'production', ...process.env}});
82+
const out = spawn(
83+
'node',
84+
[
85+
'-r',
86+
'source-map-support/register',
87+
'--max-http-header-size=20480',
88+
`${voltranConfigs.distFolder}/server/server.js`
89+
],
90+
{ env: { NODE_ENV: 'production', ...process.env } }
91+
);
8792

88-
out.stdout.on('data', (data) => {
93+
out.stdout.on('data', data => {
8994
console.log(data.toString());
9095
});
9196

92-
out.stderr.on('data', (data) => {
97+
out.stderr.on('data', data => {
9398
console.error(data.toString());
9499
});
95100

96-
out.on('close', (code) => {
101+
out.on('close', code => {
97102
console.log(`child process exited with code ${code}`);
98103
});
99104
}
@@ -110,7 +115,6 @@ function checkRequiredVariables(mergeConfigs) {
110115
}
111116

112117
export function cli(args) {
113-
console.log('SELAM');
114118
const argumentList = parseArgumentsIntoOptions(args);
115119
console.log(clc.blue(JSON.stringify(argumentList)));
116120
const voltranConfigs = argumentList.configFile ? getVoltranConfigs(argumentList.configFile) : {};
@@ -121,17 +125,17 @@ export function cli(args) {
121125
if (isValid) {
122126
const createdConfig = `module.exports = ${JSON.stringify(mergeAllConfigs)}`;
123127

124-
fs.writeFile(path.resolve(__dirname, '../voltran.config.js'), createdConfig, function (err) {
128+
fs.writeFile(path.resolve(__dirname, '../voltran.config.js'), createdConfig, function(err) {
125129
if (err) throw err;
126130

127131
console.log('File is created successfully.', mergeAllConfigs.dev);
128132

129133
if (mergeAllConfigs.dev) {
130134
runDevelopmentMode();
131135
} else {
132-
argumentList.noBundle ?
133-
serve(voltranConfigs) :
134-
runProductionMode(mergeAllConfigs, argumentList.bundle);
136+
argumentList.noBundle
137+
? serve(voltranConfigs)
138+
: runProductionMode(mergeAllConfigs, argumentList.bundle);
135139
}
136140
});
137141
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "voltranjs",
3-
"version": "1.2.0-beta.7",
3+
"version": "1.2.0-beta.11",
44
"main": "src/index.js",
55
"author": "Hepsiburada Technology Team",
66
"bin": {

src/universal/utils/baseRenderHtml.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { QUERY_PARAMS } from './constants';
2+
13
const appConfig = require('__APP_CONFIG__');
24
const assets = require('__ASSETS_FILE_PATH__');
35
const voltranConfig = require('../../../voltran.config');
4-
import { QUERY_PARAMS } from './constants';
56

67
const assetsBaseUrl = !appConfig.mediaUrl ? appConfig.baseUrl : '';
78
const assetsPrefix = appConfig.mediaUrl.length ? appConfig.mediaUrl : appConfig.baseUrl;
@@ -41,6 +42,20 @@ if (process.env.NODE_ENV === 'production') {
4142
});
4243
}
4344

45+
const getSplitChunks = () => {
46+
const chunks =
47+
voltranConfig?.splitChunkNames?.filter(chunk => `${assetsBaseUrl}${assets?.[chunk]?.js}`) || [];
48+
49+
if (chunks?.length > 0) {
50+
return chunks?.map(chunk => ({
51+
src: `${assetsBaseUrl}${assets?.[chunk]?.js}`,
52+
isAsync: false
53+
}));
54+
}
55+
56+
return [];
57+
};
58+
4459
const getScripts = (name, subComponentFiles) => {
4560
const subComponentFilesScripts = subComponentFiles?.scripts;
4661
const scripts = [
@@ -51,7 +66,8 @@ const getScripts = (name, subComponentFiles) => {
5166
{
5267
src: `${assetsBaseUrl}${assets?.[name]?.js}`,
5368
isAsync: false
54-
}
69+
},
70+
...getSplitChunks()
5571
];
5672
const mergedScripts =
5773
subComponentFilesScripts?.length > 0 ? scripts.concat(subComponentFiles.scripts) : scripts;

0 commit comments

Comments
 (0)