mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-06 12:17:13 +08:00
25 lines
606 B
JavaScript
25 lines
606 B
JavaScript
|
const parser = require('@babel/parser')
|
||
|
const { default: traverse } = require('@babel/traverse')
|
||
|
const { default: generate } = require('@babel/generator')
|
||
|
|
||
|
module.exports = function terseCssr (code) {
|
||
|
if (process.env.NODE_ENV === 'production') {
|
||
|
const pattern = /[\n\t\s]+/g
|
||
|
|
||
|
const ast = parser.parse(code, {
|
||
|
sourceType: 'module'
|
||
|
})
|
||
|
|
||
|
traverse(ast, {
|
||
|
TemplateElement (path) {
|
||
|
;['raw', 'cooked'].forEach((type) => {
|
||
|
path.node.value[type] = path.node.value[type].replace(pattern, '')
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return generate(ast).code
|
||
|
}
|
||
|
return code
|
||
|
}
|