Last active
July 14, 2022 04:12
-
-
Save sokolovstas/a31ff0d5142b047b1d6db3a855f273fd to your computer and use it in GitHub Desktop.
html preprocess for Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////// 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