@intlayer/webpack 1.0.0
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/LICENSE +21 -0
- package/dist/cjs/index.cjs +46 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/scripts/bundle.cjs +68 -0
- package/dist/cjs/scripts/bundle.cjs.map +1 -0
- package/dist/cjs/scripts/index.cjs +33 -0
- package/dist/cjs/scripts/index.cjs.map +1 -0
- package/dist/cjs/scripts/startServer.cjs +44 -0
- package/dist/cjs/scripts/startServer.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +92 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +35 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +83 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +122 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +41 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +50 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +47 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +70 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +112 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +1 -0
- package/dist/cjs/utils.cjs +53 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/webpack-plugin.cjs +184 -0
- package/dist/cjs/webpack-plugin.cjs.map +1 -0
- package/dist/cjs/webpack.config.cjs +180 -0
- package/dist/cjs/webpack.config.cjs.map +1 -0
- package/dist/esm/index.d.mts +9 -0
- package/dist/esm/index.mjs +12 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/scripts/bundle.d.mts +7 -0
- package/dist/esm/scripts/bundle.mjs +35 -0
- package/dist/esm/scripts/bundle.mjs.map +1 -0
- package/dist/esm/scripts/index.d.mts +3 -0
- package/dist/esm/scripts/index.mjs +3 -0
- package/dist/esm/scripts/index.mjs.map +1 -0
- package/dist/esm/scripts/startServer.d.mts +5 -0
- package/dist/esm/scripts/startServer.mjs +10 -0
- package/dist/esm/scripts/startServer.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +6 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +52 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -0
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -0
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +7 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +43 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +42 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +84 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +10 -0
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -0
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +44 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +19 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +10 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +39 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +8 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +70 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +1 -0
- package/dist/esm/utils.d.mts +4 -0
- package/dist/esm/utils.mjs +20 -0
- package/dist/esm/utils.mjs.map +1 -0
- package/dist/esm/webpack-plugin.d.mts +15 -0
- package/dist/esm/webpack-plugin.mjs +145 -0
- package/dist/esm/webpack-plugin.mjs.map +1 -0
- package/dist/esm/webpack.config.d.mts +7 -0
- package/dist/esm/webpack.config.mjs +136 -0
- package/dist/esm/webpack.config.mjs.map +1 -0
- package/package.json +97 -0
- package/src/index.ts +12 -0
- package/src/scripts/bundle.ts +44 -0
- package/src/scripts/index.ts +2 -0
- package/src/scripts/startServer.ts +14 -0
- package/src/transpiler/dictionary_to_main/createDictionaryList.ts +65 -0
- package/src/transpiler/dictionary_to_main/index.ts +1 -0
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +70 -0
- package/src/transpiler/dictionary_to_type/createType.ts +140 -0
- package/src/transpiler/dictionary_to_type/index.ts +2 -0
- package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +60 -0
- package/src/transpiler/intlater_module_to_dictionary/index.ts +3 -0
- package/src/transpiler/intlater_module_to_dictionary/processModule.ts +69 -0
- package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +107 -0
- package/src/utils.ts +26 -0
- package/src/webpack-plugin.ts +185 -0
- package/src/webpack.config.ts +149 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { getConfiguration } from '@intlayer/config';
|
|
5
|
+
import type { ContentModule } from '@intlayer/core';
|
|
6
|
+
import { extractObjectsWithId } from './extractNestedJSON';
|
|
7
|
+
import { processModule } from './processModule';
|
|
8
|
+
|
|
9
|
+
const { content } = getConfiguration();
|
|
10
|
+
const { dictionariesDir, bundleFileExtension } = content;
|
|
11
|
+
|
|
12
|
+
const loadBundledModule = async (bundledEntryPath: string) => {
|
|
13
|
+
const entryFilePath = resolve(bundledEntryPath);
|
|
14
|
+
|
|
15
|
+
const isEntryFilePathExist = existsSync(entryFilePath);
|
|
16
|
+
|
|
17
|
+
if (!isEntryFilePathExist) {
|
|
18
|
+
console.error('Entry file not found. ' + entryFilePath);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);
|
|
23
|
+
|
|
24
|
+
if (!isEntryPathValid) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// Remove the module from the cache
|
|
30
|
+
delete require.cache[entryFilePath];
|
|
31
|
+
|
|
32
|
+
// Require the module anew
|
|
33
|
+
const entry = await import(entryFilePath);
|
|
34
|
+
|
|
35
|
+
let result: ContentModule | undefined;
|
|
36
|
+
|
|
37
|
+
if (entry.default) {
|
|
38
|
+
// JS or TS file
|
|
39
|
+
result = await processModule(entryFilePath);
|
|
40
|
+
} else {
|
|
41
|
+
// JSON file
|
|
42
|
+
result = entry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error(`Error transpiling ${entryFilePath}:`, err);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const buildDictionary = async (dictionaries: ContentModule[]) => {
|
|
52
|
+
const resultDictionariesPaths: string[] = [];
|
|
53
|
+
|
|
54
|
+
for await (const content of dictionaries) {
|
|
55
|
+
const contentString = JSON.stringify(content);
|
|
56
|
+
|
|
57
|
+
const id = content.id;
|
|
58
|
+
const outputFileName = `${id}.json`;
|
|
59
|
+
const resultFilePath = resolve(dictionariesDir, outputFileName);
|
|
60
|
+
|
|
61
|
+
// Create the json file
|
|
62
|
+
await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {
|
|
63
|
+
console.error(`Error creating ${outputFileName}:`, err);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
resultDictionariesPaths.push(resultFilePath);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return resultDictionariesPaths;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* This function transpile the bundled code to to make dictionaries as JSON files
|
|
74
|
+
*/
|
|
75
|
+
export const transpileBundledCode = async (
|
|
76
|
+
bundledEntriesPaths: string[] | string
|
|
77
|
+
) => {
|
|
78
|
+
const resultDictionariesPaths: string[] = [];
|
|
79
|
+
|
|
80
|
+
if (typeof bundledEntriesPaths === 'string') {
|
|
81
|
+
bundledEntriesPaths = [bundledEntriesPaths];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const filteredBundledEntriesPaths: string[] = bundledEntriesPaths.filter(
|
|
85
|
+
// Filter js files;
|
|
86
|
+
(bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Create the dictionaries folder if it doesn't exist
|
|
90
|
+
await mkdir(resolve(dictionariesDir), { recursive: true });
|
|
91
|
+
|
|
92
|
+
for await (const bundledEntryPath of filteredBundledEntriesPaths) {
|
|
93
|
+
const result = await loadBundledModule(bundledEntryPath);
|
|
94
|
+
|
|
95
|
+
if (!result) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const nestedContent: ContentModule[] = extractObjectsWithId(result);
|
|
100
|
+
|
|
101
|
+
const dictionariesPaths: string[] = await buildDictionary(nestedContent);
|
|
102
|
+
|
|
103
|
+
resultDictionariesPaths.push(...dictionariesPaths);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return resultDictionariesPaths;
|
|
107
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SHA3, enc } from 'crypto-js';
|
|
2
|
+
|
|
3
|
+
export const getFileHash = (filePath: string) => {
|
|
4
|
+
const hash = SHA3(filePath);
|
|
5
|
+
|
|
6
|
+
return hash
|
|
7
|
+
.toString(enc.Base64)
|
|
8
|
+
.replace(/[^A-Z\d]/gi, '')
|
|
9
|
+
.substring(0, 20);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const transformToCamelCase = (string: string): string => {
|
|
13
|
+
// Split the string into words using a regex that finds spaces, hyphens, and underscores
|
|
14
|
+
const words = string.split(/[\s\-_]+/);
|
|
15
|
+
|
|
16
|
+
// Transform each word except the first to have its first letter uppercase
|
|
17
|
+
const camelCasedWords = words.map((word, index) => {
|
|
18
|
+
if (index === 0) {
|
|
19
|
+
return word[0].toUpperCase() + word.slice(1);
|
|
20
|
+
}
|
|
21
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Join the words back together
|
|
25
|
+
return camelCasedWords.join('');
|
|
26
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { relative, resolve } from 'path';
|
|
2
|
+
import { getConfiguration } from '@intlayer/config';
|
|
3
|
+
import { sync } from 'glob';
|
|
4
|
+
import { DynamicEntryPlugin, type Compiler } from 'webpack';
|
|
5
|
+
import { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';
|
|
6
|
+
import { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';
|
|
7
|
+
import { createTypes } from './transpiler/dictionary_to_type/createType';
|
|
8
|
+
import { transpileBundledCode } from './transpiler/intlater_module_to_dictionary/transpileBundledCode';
|
|
9
|
+
import { getFileHash } from './utils';
|
|
10
|
+
|
|
11
|
+
const getRelativePath = (filePath: string) => relative(baseDir, filePath);
|
|
12
|
+
|
|
13
|
+
const getBundledFilePathFromIntlayerModule = (filePath: string): string => {
|
|
14
|
+
const hash = getFileHash(filePath);
|
|
15
|
+
|
|
16
|
+
return `${bundleDir}/${hash}${bundleFileExtension}`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const { content } = getConfiguration();
|
|
20
|
+
const { bundleDir, baseDir, bundleFileExtension, watchedFilesPatternWithPath } =
|
|
21
|
+
content;
|
|
22
|
+
|
|
23
|
+
export class IntLayerPlugin {
|
|
24
|
+
private managedFiles: Set<string>;
|
|
25
|
+
private updatedFiles: Set<string>;
|
|
26
|
+
private addedFiles: Set<string>;
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
this.managedFiles = new Set();
|
|
30
|
+
this.updatedFiles = new Set();
|
|
31
|
+
this.addedFiles = new Set();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// function to initialize the dictionaries
|
|
35
|
+
public async initDictionaries() {
|
|
36
|
+
const outputFiles = [...this.managedFiles].map((file) =>
|
|
37
|
+
resolve(bundleDir, file)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const dictionaries = (await transpileBundledCode(outputFiles)) ?? [];
|
|
41
|
+
|
|
42
|
+
console.info(
|
|
43
|
+
`Dictionaries: \n ${dictionaries.map(getRelativePath).join('\n')}`
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
console.info('Building TypeScript types...');
|
|
47
|
+
createTypes(dictionaries);
|
|
48
|
+
|
|
49
|
+
console.info('Building type index...');
|
|
50
|
+
createModuleAugmentation();
|
|
51
|
+
|
|
52
|
+
console.info('Building main...');
|
|
53
|
+
createDictionaryList();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// function to process when intlayer module files content are changed
|
|
57
|
+
public async processFilesChanges() {
|
|
58
|
+
const dictionaries =
|
|
59
|
+
(await transpileBundledCode([...this.updatedFiles])) ?? [];
|
|
60
|
+
|
|
61
|
+
console.info(
|
|
62
|
+
`Updated dictionaries: \n ${dictionaries.map(getRelativePath).join('\n')}`
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
console.info('Updating TypeScript types...');
|
|
66
|
+
createTypes(dictionaries);
|
|
67
|
+
|
|
68
|
+
this.updatedFiles.clear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// function to process when new intlayer module is detected
|
|
72
|
+
public async processNewFiles() {
|
|
73
|
+
const dictionaries =
|
|
74
|
+
(await transpileBundledCode([...this.addedFiles])) ?? [];
|
|
75
|
+
|
|
76
|
+
console.info(
|
|
77
|
+
`New dictionaries: \n ${dictionaries.map(getRelativePath).join('\n')}`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
console.info('Building TypeScript types...');
|
|
81
|
+
createTypes(dictionaries);
|
|
82
|
+
|
|
83
|
+
console.info('Building type index...');
|
|
84
|
+
createModuleAugmentation();
|
|
85
|
+
|
|
86
|
+
console.info('Building main...');
|
|
87
|
+
createDictionaryList();
|
|
88
|
+
|
|
89
|
+
this.managedFiles = new Set([...this.managedFiles, ...this.addedFiles]);
|
|
90
|
+
this.addedFiles.clear();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public async detectFileAddedOrRemoved() {
|
|
94
|
+
const filesFound: string[] = [];
|
|
95
|
+
|
|
96
|
+
for (const pattern of watchedFilesPatternWithPath) {
|
|
97
|
+
sync(pattern).map((file) => filesFound.push(file));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Detect new files by comparing with files emitted in previous compilation
|
|
101
|
+
const newFiles = new Set(
|
|
102
|
+
filesFound.filter((x) => !this.managedFiles.has(x))
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const removedFiles = new Set(
|
|
106
|
+
[...this.managedFiles].filter((x) => !filesFound.includes(x))
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
// Check if there is new files
|
|
111
|
+
newFiles.size > 0
|
|
112
|
+
) {
|
|
113
|
+
console.info('New files:', [...newFiles]);
|
|
114
|
+
|
|
115
|
+
this.addedFiles = newFiles;
|
|
116
|
+
|
|
117
|
+
await this.processNewFiles();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
// Check if there is removed files
|
|
122
|
+
removedFiles.size > 0
|
|
123
|
+
) {
|
|
124
|
+
console.info('Removed files:', [...removedFiles]);
|
|
125
|
+
|
|
126
|
+
this.managedFiles = new Set(
|
|
127
|
+
[...this.managedFiles].filter((x) => !removedFiles.has(x))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// After the compilation, transpile the changed files if any
|
|
132
|
+
if (this.updatedFiles.size > 0) {
|
|
133
|
+
await this.processFilesChanges();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
apply(compiler: Compiler): void {
|
|
138
|
+
compiler.hooks.entryOption.tap('EntryOptionPlugin', (context, entry) => {
|
|
139
|
+
if (typeof entry === 'function') {
|
|
140
|
+
// DynamicEntryPlugin is used to add entries at runtime when files are created, updated or deleted
|
|
141
|
+
new DynamicEntryPlugin(context, entry).apply(compiler);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return true;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
compiler.hooks.afterEmit.tapAsync(
|
|
148
|
+
'IntLayerPlugin - Process dictionaries',
|
|
149
|
+
async (compilation, callback) => {
|
|
150
|
+
// Get a set of files that will be emitted in this compilation
|
|
151
|
+
const currentEmitFiles = new Set(Object.keys(compilation.assets));
|
|
152
|
+
|
|
153
|
+
if (
|
|
154
|
+
// Check if this first load
|
|
155
|
+
!this.managedFiles.size
|
|
156
|
+
) {
|
|
157
|
+
// Update previousEmitFiles for the next compilation
|
|
158
|
+
this.managedFiles = currentEmitFiles;
|
|
159
|
+
|
|
160
|
+
await this.initDictionaries();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await this.detectFileAddedOrRemoved();
|
|
164
|
+
|
|
165
|
+
callback();
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// Detect modified files on watch mode
|
|
170
|
+
compiler.hooks.watchRun.tap(
|
|
171
|
+
'IntLayerPlugin - Change detection',
|
|
172
|
+
(compilation) => {
|
|
173
|
+
if (compilation.modifiedFiles) {
|
|
174
|
+
const updatedFiles = Array.from(compilation.modifiedFiles);
|
|
175
|
+
|
|
176
|
+
const outputFileNames = updatedFiles.map(
|
|
177
|
+
getBundledFilePathFromIntlayerModule
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
this.updatedFiles = new Set(outputFileNames);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { getConfiguration } from '@intlayer/config';
|
|
3
|
+
import { sync } from 'glob';
|
|
4
|
+
import type { Configuration as WebPackConfiguration } from 'webpack';
|
|
5
|
+
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
|
|
6
|
+
import { getFileHash } from './utils';
|
|
7
|
+
import { IntLayerPlugin } from './webpack-plugin';
|
|
8
|
+
|
|
9
|
+
const { content } = getConfiguration({
|
|
10
|
+
verbose: true,
|
|
11
|
+
});
|
|
12
|
+
const { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;
|
|
13
|
+
|
|
14
|
+
const getEntry = (): Record<string, string> =>
|
|
15
|
+
sync(watchedFilesPatternWithPath).reduce(
|
|
16
|
+
(obj, el) => {
|
|
17
|
+
const hash = getFileHash(el);
|
|
18
|
+
|
|
19
|
+
obj[hash] = el;
|
|
20
|
+
return obj;
|
|
21
|
+
},
|
|
22
|
+
{} as Record<string, string>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// For web interface
|
|
26
|
+
export const devServerConfig: DevServerConfiguration = {
|
|
27
|
+
// Enable hot module replacement
|
|
28
|
+
hot: true,
|
|
29
|
+
// Open the browser
|
|
30
|
+
open: false,
|
|
31
|
+
liveReload: false,
|
|
32
|
+
|
|
33
|
+
// Enable compression
|
|
34
|
+
compress: true,
|
|
35
|
+
|
|
36
|
+
// History API fallback
|
|
37
|
+
historyApiFallback: false,
|
|
38
|
+
|
|
39
|
+
// Host and port
|
|
40
|
+
host: 'localhost',
|
|
41
|
+
port: 8080,
|
|
42
|
+
|
|
43
|
+
watchFiles: './src/', // watchedFilesPatternWithPath,
|
|
44
|
+
|
|
45
|
+
devMiddleware: {
|
|
46
|
+
// Enable write to disk to reuse the output
|
|
47
|
+
writeToDisk: true,
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// Content base
|
|
51
|
+
static: {
|
|
52
|
+
directory: bundleDir,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const webpackConfig: WebPackConfiguration = {
|
|
57
|
+
// Define the environment mode (development or production)
|
|
58
|
+
mode: 'production', // or 'production'
|
|
59
|
+
// Entry point of the application
|
|
60
|
+
target: 'node', // Specifies the target environment
|
|
61
|
+
|
|
62
|
+
entry: getEntry,
|
|
63
|
+
output: {
|
|
64
|
+
clean: true, // Clean the output directory before emit
|
|
65
|
+
library: 'IntlLayerContent',
|
|
66
|
+
libraryTarget: 'umd',
|
|
67
|
+
filename: `[name]${bundleFileExtension}`,
|
|
68
|
+
path: bundleDir,
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
cache: false,
|
|
72
|
+
|
|
73
|
+
// devtool: 'source-map',
|
|
74
|
+
|
|
75
|
+
// stats: {
|
|
76
|
+
// preset: 'errors-only',
|
|
77
|
+
// warnings: false,
|
|
78
|
+
// },
|
|
79
|
+
ignoreWarnings: [/./],
|
|
80
|
+
resolve: {
|
|
81
|
+
// Resolve TypeScript, JavaScript and JSON files
|
|
82
|
+
extensions: ['.ts', '.js', '.json', '.wasm', '.ts', '.tsx', '.mjs', '.cjs'],
|
|
83
|
+
modules: [
|
|
84
|
+
// To find the loader module
|
|
85
|
+
join(__dirname, '..', 'node_modules'), // In the project node_modules
|
|
86
|
+
join(process.cwd(), 'node_modules'), // In the project node_modules
|
|
87
|
+
join(process.cwd(), 'node_modules', 'intlayer-cli', 'node_modules'), // Or via another project by importing intlayer
|
|
88
|
+
join(
|
|
89
|
+
process.cwd(),
|
|
90
|
+
'node_modules',
|
|
91
|
+
'intlayer-cli',
|
|
92
|
+
'node_modules',
|
|
93
|
+
'@intlayer/webpack',
|
|
94
|
+
'node_modules'
|
|
95
|
+
), // Or via another project by importing intlayer
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
resolveLoader: {
|
|
100
|
+
// Configure how Webpack finds `loader` modules.
|
|
101
|
+
modules: [
|
|
102
|
+
// To find the loader module
|
|
103
|
+
join(process.cwd(), 'node_modules'), // In the project node_modules
|
|
104
|
+
join(process.cwd(), 'node_modules', '@intlayer/webpack', 'node_modules'), // Or via another project by importing @intlayer/webpack
|
|
105
|
+
join(
|
|
106
|
+
process.cwd(),
|
|
107
|
+
'node_modules',
|
|
108
|
+
'intlayer-cli',
|
|
109
|
+
'node_modules',
|
|
110
|
+
'@intlayer/webpack',
|
|
111
|
+
'node_modules'
|
|
112
|
+
), // Or via another project by importing intlayer
|
|
113
|
+
],
|
|
114
|
+
// roots: [
|
|
115
|
+
// join(process.cwd()), // Project context
|
|
116
|
+
// join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
|
|
117
|
+
// join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project
|
|
118
|
+
// ],
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
module: {
|
|
122
|
+
rules: [
|
|
123
|
+
{
|
|
124
|
+
test: /\.node$/,
|
|
125
|
+
loader: 'node-loader',
|
|
126
|
+
},
|
|
127
|
+
// Use esbuild to compile JavaScript & TypeScript
|
|
128
|
+
{
|
|
129
|
+
// Match `.js`, `.jsx`, `.ts` or `.tsx` files
|
|
130
|
+
test: /\.[jt]sx?$/,
|
|
131
|
+
loader: 'esbuild-loader',
|
|
132
|
+
options: {
|
|
133
|
+
// JavaScript version to compile to
|
|
134
|
+
target: 'es2015',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
// JSON files are supported natively by Webpack 5, no specific loader required
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
devServer: devServerConfig,
|
|
142
|
+
|
|
143
|
+
plugins: [
|
|
144
|
+
new IntLayerPlugin(),
|
|
145
|
+
// new HotModuleReplacementPlugin()
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default webpackConfig;
|