Open StErMi opened 4 years ago
I don't think it would be a good practice to include files that in some types of applications, need to be read at different times. For example, an application that reads a particular file, then makes an edit and saves it again. It would be confusing to specify files that should or should not be included in the final .js file, unless ncc wants to stop being a simple CLI in the future as it says.
In my example, those JSON files are config files and translations files. At the moment I don't have a solution in mind because I cannot modify the framework and I'm not allowed by NCC to include them in the build process. Do you have any suggestions? Those files would be read-only.
When the files are referenced somewhere in your code, e.g.
fs.readFileSync(__dirname + 'path/to/your.json')
The underlying webpack-asset-relocator-loader should be able to find it & add it into the bundle.
If want to read a specific path, that should not be modified by ncc, you can use __non_webpack_require__
:
const translations = __non_webpack_require__('static/path/not/altered/by/ncc/translations.json')
But keep in mind that static/path/not/altered/by/ncc/translations.json
is not included in the final bundle (Has to be added manually to the bundle) because webpack/ncc does not resolve the content of this require.
Hi @ofhouse the problem is that those files are not directly required in that way by the framework. They're going to load all those files automatically from a specific path. So there's no way to bundle them if the framework does not change how it works?
@StErMi Is the framework public available so that you can post a link? It's hard to guess what's going wrong in your case without an example.
ncc covers a lot of cases but after all it's all based on static code analyzing so there is always a chance that something is missed by the algorithm. To address this issue it would be necessary to share at least the part of the code where the framework loads the missing files.
Then we can find out whether it is something that could be covered by static code analyzing from ncc or if changes to the framework are needed.
When the files are referenced somewhere in your code, e.g.
fs.readFileSync(__dirname + 'path/to/your.json')
The underlying webpack-asset-relocator-loader should be able to find it & add it into the bundle.
Hate to dig up an old topic, but I also ran into this recently when upgrading one of my projects from JavaScript to TypeScript.
The JavaScript version had copied some .sh and .ps1 scripts into the bundle, but the TypeScript version no longer does.
In the final index.js bundle I can also see that the required calls had also been replaced with just a simple path.join
which lead me to suspect that the asset relocator somehow lost the reference.
[Edit] I was able to fix this. I realized that I didn't need to compile separately then run the ncc build on that. Instead run ncc build directly on index.ts.
Hi all,
the underlying framework that I'm using assumes that I have some JSON and TS file in a specific path.
Would it be possible to force include some files or some files in a specific platform in the final build?