Skip to content

Commit

Permalink
update webpack to build without modules directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sudharsan-selvaraj committed Feb 6, 2024
1 parent 1ec3271 commit 14ff3a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export function safeParseJson(jsonString: string) {

export async function loadExternalModules(): Promise<IExternalModuleLoader> {
// eslint-disable-next-line
// @ts-ignore
return import(/* webpackMode: "eager" */ './modules')
.then((externalModule) => {
console.log(externalModule);
Expand Down
14 changes: 9 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ const filesToKeepInLib = [/src\/scripts/g, /config.js/g, /main.js/g];
const filesToGenerate = [
{
override: true,
path: '${LIB_DIRECTORY}/src/main.js',
path: 'lib/src/main.js',
contents: 'module.exports = { DevicePlugin : require("../bundle.js").default }',
},
{
override: false,
path: 'lib/src/modules/index.js',
contents: 'module.exports = require("../fake-module-loader.js").FakeModuleLoader;',
},
];

//Remove all files that are already bundled from lib folder
Expand All @@ -30,9 +35,9 @@ const CleanUpLibFolder = new RemovePlugin({

class DynamicFileGenerator {
apply(compiler) {
compiler.hooks.emit.tapAsync('CreateFilePlugin', (compilation, callback) => {
compiler.hooks.compile.tap('CreateFilePlugin', () => {
for (const file of filesToGenerate) {
const fPath = file.path.replace('${LIB_DIRECTORY}', compilation.outputOptions.path);
const fPath = file.path;
const dir = path.dirname(fPath);
if (!file.override && fs.existsSync(fPath)) {
break;
Expand All @@ -42,7 +47,6 @@ class DynamicFileGenerator {
}
fs.writeFileSync(fPath, file.contents);
}
callback();
});
}
}
Expand All @@ -65,14 +69,14 @@ module.exports = {
mode: 'production',
devtool: 'nosources-source-map',
plugins: [
new DynamicFileGenerator(),
new WebpackObfuscator({
rotateStringArray: true,
splitStrings: true,
target: 'node',
identifierNamesGenerator: 'mangled-shuffled',
sourceMap: true,
}),
new DynamicFileGenerator(),
CleanUpLibFolder,
],
};

0 comments on commit 14ff3a3

Please sign in to comment.