preprocessor-loader
preprocessor-loader copied to clipboard
Test libraries
Hello, does it work with test libraries ?
How to use it with jest ?
Hey, not sure if you still need this, in my case, I'm using webpack with Quasar, and I don't want to compile the components using the Capacitor library when in PWA mode
First, Create a custom Webpack loader configuration for Jest. Create a file called jest-preprocessor-loader.js in your project's root directory with the following content:
module.exports = {
process(src, filename, config, options) {
const preprocessor = require('webpack-preprocessor-loader');
const params = {
capacitor: process.env.MODE === 'capacitor'
};
return preprocessor(src, filename, config, options, { params });
},
};
Then, Configure Jest to use the custom loader in your jest.config.js file:
module.exports = {
// maybe change "vue" to other file extension based on your needs
moduleNameMapper: {
'\\.(vue)$': '<rootDir>/jest-preprocessor-loader.js',
},
// ...
};
And it works like a champ