File tree Expand file tree Collapse file tree 3 files changed +93
-0
lines changed Expand file tree Collapse file tree 3 files changed +93
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < link rel ="stylesheet " href ="styles.css " />
7+ < title > Code Splitting App</ title >
8+ </ head >
9+ < body >
10+ < div class ="container ">
11+ < h1 > Code Splitting App</ h1 >
12+ < textarea
13+ id ="inputCode "
14+ placeholder ="Paste your JavaScript code here... "
15+ > </ textarea >
16+ < button onclick ="performCodeSplitting() ">
17+ Perform Code Splitting
18+ </ button >
19+ < div id ="outputFiles "> </ div >
20+ </ div >
21+
22+ < script src ="script.js "> </ script >
23+ </ body >
24+ </ html >
Original file line number Diff line number Diff line change 1+ function performCodeSplitting ( ) {
2+ const inputCode = document . getElementById ( "inputCode" ) . value ;
3+
4+ if ( ! inputCode . trim ( ) ) {
5+ alert ( "Please enter JavaScript code for code splitting." ) ;
6+ return ;
7+ }
8+
9+ try {
10+ const splitFiles = splitCode ( inputCode ) ;
11+ displayResult ( splitFiles ) ;
12+ } catch ( error ) {
13+ alert ( `Error during code splitting: ${ error . message } ` ) ;
14+ }
15+ }
16+
17+ function splitCode ( code ) {
18+ // Placeholder for code splitting logic
19+ // In a real-world scenario, you would use a build tool like Webpack to handle code splitting.
20+ // Here, we'll use a simplified logic to illustrate the concept.
21+
22+ const splitFiles = code . split ( "\n\n" ) ; // Split the code into files based on double line breaks
23+
24+ if ( splitFiles . length > 1 ) {
25+ return splitFiles ;
26+ } else {
27+ throw new Error ( "Failed to perform code splitting." ) ;
28+ }
29+ }
30+
31+ function displayResult ( files ) {
32+ const outputFiles = document . getElementById ( "outputFiles" ) ;
33+ outputFiles . innerHTML = "<strong>Split Files:</strong>" ;
34+
35+ files . forEach ( ( file , index ) => {
36+ outputFiles . innerHTML += `<div><strong>File ${
37+ index + 1
38+ } :</strong><pre>${ file } </pre></div>`;
39+ } ) ;
40+ }
Original file line number Diff line number Diff line change 1+ body {
2+ font-family : Arial, sans-serif;
3+ display : flex;
4+ align-items : center;
5+ justify-content : center;
6+ height : 100vh ;
7+ margin : 0 ;
8+ }
9+
10+ .container {
11+ text-align : center;
12+ }
13+
14+ textarea {
15+ width : 100% ;
16+ height : 150px ;
17+ margin : 10px 0 ;
18+ }
19+
20+ button {
21+ padding : 10px 20px ;
22+ font-size : 16px ;
23+ margin : 10px ;
24+ }
25+
26+ # outputFiles {
27+ margin-top : 20px ;
28+ font-size : 18px ;
29+ }
You can’t perform that action at this time.
0 commit comments