From 25bba0c9aeec6e6e41281e3ae2e69fbd0f34ba48 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 12 Mar 2020 18:43:54 +0800 Subject: [PATCH] fix(wxs): base64(wxs code) --- .../dist/parseCustomBlocks.js | 2 +- .../webpack-uni-app-loader/filter-modules-template.js | 11 +++++++++-- packages/webpack-uni-mp-loader/lib/template-new.js | 9 ++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js b/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js index 0c32f1b8a2..063e637e53 100644 --- a/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js +++ b/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js @@ -62,7 +62,7 @@ module.exports = function parseCustomBlocks(descriptor, options) { filterModule.attrs.src = normalizeNodeModules(filterModule.attrs.src) } }) - descriptor.template.attrs['filter-modules'] = JSON.stringify(filterModules) + descriptor.template.attrs['filter-modules'] = Buffer.from(JSON.stringify(filterModules)).toString('base64') } return descriptor diff --git a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/filter-modules-template.js b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/filter-modules-template.js index c4dcc586b9..6d68059dee 100644 --- a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/filter-modules-template.js +++ b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/filter-modules-template.js @@ -1,13 +1,20 @@ const loaderUtils = require('loader-utils') -module.exports = function (content) { +function parseFilterModules(filterModules) { + if (filterModules) { + return JSON.parse(Buffer.from(filterModules, 'base64').toString('ascii')) + } + return {} +} + +module.exports = function(content) { this.cacheable && this.cacheable() const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options') if (vueLoaderOptions) { const params = loaderUtils.parseQuery(this.resourceQuery) /* eslint-disable no-mixed-operators */ - const filterModules = JSON.parse(params && params['filter-modules'] || '{}') + const filterModules = parseFilterModules(params && params['filter-modules']) Object.assign(vueLoaderOptions.options.compilerOptions, { filterModules: Object.keys(filterModules) }) diff --git a/packages/webpack-uni-mp-loader/lib/template-new.js b/packages/webpack-uni-mp-loader/lib/template-new.js index 9801d11f1e..37673e881a 100644 --- a/packages/webpack-uni-mp-loader/lib/template-new.js +++ b/packages/webpack-uni-mp-loader/lib/template-new.js @@ -28,6 +28,13 @@ const { const templateExt = getPlatformExts().template const filterTagName = getPlatformFilterTag() || '' + +function parseFilterModules (filterModules) { + if (filterModules) { + return JSON.parse(Buffer.from(filterModules, 'base64').toString('ascii')) + } + return {} +} module.exports = function (content) { this.cacheable && this.cacheable() @@ -41,7 +48,7 @@ module.exports = function (content) { const params = loaderUtils.parseQuery(this.resourceQuery) /* eslint-disable no-mixed-operators */ - const filterModules = JSON.parse(params && params['filter-modules'] || '{}') + const filterModules = parseFilterModules(params && params['filter-modules']) Object.assign(vueLoaderOptions.options.compilerOptions, { mp: { platform: process.env.UNI_PLATFORM -- GitLab