Skip to content

Instantly share code, notes, and snippets.

@sokolovstas
Last active July 14, 2022 04:12
Show Gist options
  • Save sokolovstas/a31ff0d5142b047b1d6db3a855f273fd to your computer and use it in GitHub Desktop.
Save sokolovstas/a31ff0d5142b047b1d6db3a855f273fd to your computer and use it in GitHub Desktop.
html preprocess for Angular
//////// extra-webpack.config.js ////////
module.exports = async (config, options) => {
process.env.MODE = config.mode;
...
config.resolveLoader.alias = {
'raw-loader': path.resolve(__dirname, 'utils/build/test-tag-purge.js'),
};
};
//////// test-tag-purge.js ////////
module.exports = function rawLoader(source) {
if (process.env.MODE === 'production') {
source = source.replace(/\[attr.test-.*?\]=".*?"/gm, '');
source = source.replace(/test-.*?=".*?"/gm, '');
}
const json = JSON.stringify(source)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
const esModule = true;
return `${esModule ? 'export default' : 'module.exports ='} ${json};`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment