Open korompaiistvan opened 2 years ago
Still don't understand why not release 2.0.0 of jest-raw-loader, as copying own node_modules/jest-raw-loader/index.js
to every project updating to jest is tedious and annoying and why was this package created in the first place then? to solve copy-paste distribution model.
Just for people looking for the solution, @glensc made a forked release: https://github.com/glensc/jest-raw-loader
Thank you ;)
(still, no reason to blame @keplersj if he has no more time on it)
we can create a custom fileTransfomer and use it
// fileTransformer.js
const path = require('path');
module.exports = {
process(sourceText, sourcePath, options) {
return {
code: `module.exports = ${JSON.stringify(path.basename(sourcePath))};`,
};
},
};
module.exports = {
transform: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/fileTransformer.js',
},
};
we can create a custom fileTransfomer and use it
Thanks, that seems to be working for our project. But why not use the simpler syntax suggested by @korompaiistvan ?
module.exports = {
process: content => { return { code: "module.exports = " + JSON.stringify(content)}}
};
It seems Jest 28 introduced a breaking change that renders this module unusable with that jest version. Trying to import a string from a text file gives the following error:
The problem is solved if I patch the contents of node_modules/jest/index.js from:
To:
I think this change would be backwards compatible with earlier version of jest until at least v21 but I did not test this in detail, only looked at the type definitions from the v21.0 release.
May I submit a pull request for this change?