From 6a68f4e981e225d0364b789730f9f5f976b65640 Mon Sep 17 00:00:00 2001 From: Kevin Marrec Date: Sun, 20 Jan 2019 22:19:53 +0100 Subject: [PATCH] fix(webpack): prevent terser mangling html/vue reserved tags (#4821) --- packages/webpack/src/config/base.js | 5 +++++ packages/webpack/src/utils/index.js | 3 +++ packages/webpack/src/utils/reserved-tags.js | 23 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 packages/webpack/src/utils/index.js create mode 100644 packages/webpack/src/utils/reserved-tags.js diff --git a/packages/webpack/src/config/base.js b/packages/webpack/src/config/base.js index 20672940cb..843d164e87 100644 --- a/packages/webpack/src/config/base.js +++ b/packages/webpack/src/config/base.js @@ -17,6 +17,8 @@ import PerfLoader from '../utils/perf-loader' import StyleLoader from '../utils/style-loader' import WarnFixPlugin from '../plugins/warnfix' +import { reservedVueTags } from '../utils/reserved-tags' + export default class WebpackBaseConfig { constructor(builder, options) { this.name = options.name @@ -156,6 +158,9 @@ export default class WebpackBaseConfig { }, output: { comments: /^\**!|@preserve|@license|@cc_on/ + }, + mangle: { + reserved: reservedVueTags } } }, this.options.build.terser)) diff --git a/packages/webpack/src/utils/index.js b/packages/webpack/src/utils/index.js new file mode 100644 index 0000000000..1a98c709f2 --- /dev/null +++ b/packages/webpack/src/utils/index.js @@ -0,0 +1,3 @@ +export { default as PerfLoader } from './perf-loader' +export { default as StyleLoader } from './style-loader' +export { reservedVueTags } from './reserved-tags' diff --git a/packages/webpack/src/utils/reserved-tags.js b/packages/webpack/src/utils/reserved-tags.js new file mode 100644 index 0000000000..a29d1b9795 --- /dev/null +++ b/packages/webpack/src/utils/reserved-tags.js @@ -0,0 +1,23 @@ +export const reservedVueTags = [ + // HTML tags + 'html', 'body', 'base', 'head', 'link', 'meta', 'style', 'title', 'address', + 'article', 'aside', 'footer', 'header', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', + 'hgroup', 'nav', 'section', 'div', 'dd', 'dl', 'dt', 'figcaption', 'figure', + 'picture', 'hr', 'img', 'li', 'main', 'ol', 'p', 'pre', 'ul', 'a', 'b', 'abbr', + 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', 'mark', + 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', + 'sup', 'time', 'u', 'var', 'wbr', 'area', 'audio', 'map', 'track', 'video', + 'embed', 'object', 'param', 'source', 'canvas', 'script', 'noscript', 'del', + 'ins', 'caption', 'col', 'colgroup', 'table', 'thead', 'tbody', 'td', 'th', 'tr', + 'button', 'datalist', 'fieldset', 'form', 'input', 'label', 'legend', 'meter', + 'optgroup', 'option', 'output', 'progress', 'select', 'textarea', 'details', + 'dialog', 'menu', 'menuitem', 'summary', 'content', 'element', 'shadow', 'template', + 'blockquote', 'iframe', 'tfoot', + // SVG tags + 'svg', 'animate', 'circle', 'clippath', 'cursor', 'defs', 'desc', 'ellipse', 'filter', + 'font-face', 'foreignObject', 'g', 'glyph', 'image', 'line', 'marker', 'mask', + 'missing-glyph', 'path', 'pattern', 'polygon', 'polyline', 'rect', 'switch', 'symbol', + 'text', 'textpath', 'tspan', 'use', 'view', + // Vue built-in tags + 'slot', 'component' +]