diff --git a/packages/uni-cli-shared/lib/index.js b/packages/uni-cli-shared/lib/index.js index 18081be0eca19c693e60fabbe4423bd0122ee374..771e8bcd2d423cc7ae31a837e5792ebb0c26fe29 100644 --- a/packages/uni-cli-shared/lib/index.js +++ b/packages/uni-cli-shared/lib/index.js @@ -49,7 +49,6 @@ const { getPlatformExts, getPlatformTarget, getPlatformVue, - getPlatformCompiler, getShadowCss, getPlatformCssVars, getPlatformCssnano, @@ -99,7 +98,6 @@ module.exports = { getShadowCss, getPlatformCssVars, getPlatformCssnano, - getPlatformCompiler, getShadowTemplate, parsePagesJson, parseManifestJson, diff --git a/packages/uni-cli-shared/lib/platform.js b/packages/uni-cli-shared/lib/platform.js index 61e808d356d6fa558284f0d4b84fba2dbea2f09a..466717d6ddfd0d78d00900fbb262b6d258041285 100644 --- a/packages/uni-cli-shared/lib/platform.js +++ b/packages/uni-cli-shared/lib/platform.js @@ -11,12 +11,6 @@ const { } = require('./scss') const uniRuntime = '@dcloudio/vue-cli-plugin-uni/packages/mp-vue' -const mpvueRuntime = '@dcloudio/vue-cli-plugin-uni/packages/mpvue' -const megaloRuntime = '@dcloudio/vue-cli-plugin-uni/packages/megalo' - -const uniCompiler = '@dcloudio/uni-template-compiler' -const mpvueCompiler = '@dcloudio/vue-cli-plugin-uni/packages/mpvue-template-compiler' -const megaloCompiler = '@megalo/template-compiler' function getShadowCss () { let tagName = 'page' @@ -94,7 +88,6 @@ const PLATFORMS = { exts: false, vue: '@dcloudio/vue-cli-plugin-uni/packages/h5-vue', compiler: false, - megalo: false, filterTag: 'wxs', subPackages: false, cssVars: { @@ -149,9 +142,6 @@ const PLATFORMS = { template: '.wxml', filter: '.wxs' }, - vue: mpvueRuntime, - compiler: mpvueCompiler, - megalo: false, filterTag: 'wxs', subPackages: false, cssVars: {}, @@ -203,9 +193,6 @@ const PLATFORMS = { template: '.qml', filter: '.wxs' }, - vue: mpvueRuntime, - compiler: mpvueCompiler, - megalo: false, filterTag: 'wxs', subPackages: true, cssVars: { @@ -230,9 +217,6 @@ const PLATFORMS = { template: '.wxml', filter: '.wxs' }, - vue: mpvueRuntime, - compiler: mpvueCompiler, - megalo: false, filterTag: 'wxs', subPackages: true, cssVars: { @@ -267,9 +251,6 @@ const PLATFORMS = { template: '.swan', filter: '.filter.js' }, - vue: megaloRuntime, - compiler: megaloCompiler, - megalo: 'swan', filterTag: 'filter', subPackages: true, cssVars: { @@ -294,9 +275,6 @@ const PLATFORMS = { template: '.axml', filter: '.sjs' }, - vue: megaloRuntime, - compiler: megaloCompiler, - megalo: 'alipay', filterTag: 'sjs', subPackages: true, cssVars: { @@ -319,9 +297,6 @@ const PLATFORMS = { style: '.ttss', template: '.ttml' }, - vue: megaloRuntime, - compiler: megaloCompiler, - megalo: 'tt', subPackages: false, cssVars: { '--status-bar-height': '25px', @@ -580,16 +555,6 @@ module.exports = { } return platform.vue }, - getPlatformCompiler () { - if ( - process.env.UNI_USING_COMPONENTS || - process.env.UNI_PLATFORM === 'h5' || - process.env.UNI_PLATFORM === 'quickapp' - ) { - return require(uniCompiler) - } - return require(platform.compiler) - }, getPlatformCssVars () { return platform.cssVars }, diff --git a/packages/uni-cli-shared/lib/vue-loader.js b/packages/uni-cli-shared/lib/vue-loader.js new file mode 100644 index 0000000000000000000000000000000000000000..ed0c123d01288392dc4999a44a7daf18d50f17c6 --- /dev/null +++ b/packages/uni-cli-shared/lib/vue-loader.js @@ -0,0 +1,22 @@ +const defaultOptions = { + compiler: require('@dcloudio/uni-template-compiler'), + hotReload: false, + cacheDirectory: false, + cacheIdentifier: false +} + +const defaultCompilerOptions = { + preserveWhitespace: false +} + +module.exports = { + test: [/\.vue$/, /\.nvue$/], + loader: require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vue-loader'), + options (options = {}, compilerOptions = {}) { + return Object.assign({}, + defaultOptions, + options, { + compilerOptions: Object.assign({}, defaultCompilerOptions, compilerOptions) + }) + } +} diff --git a/packages/uni-quickapp/lib/chain-webpack.js b/packages/uni-quickapp/lib/chain-webpack.js index d6634407c2c66cf9e0927d3ae79897265b49574b..96f3d1791c2d0b62e3eadecf6f2f5e83a9b47043 100644 --- a/packages/uni-quickapp/lib/chain-webpack.js +++ b/packages/uni-quickapp/lib/chain-webpack.js @@ -1,20 +1,15 @@ +const vueLoader = require('@dcloudio/uni-cli-shared/lib/vue-loader') + module.exports = config => { config.module .rule('vue') - .test([/\.vue$/, /\.nvue$/]) + .test(vueLoader.test) .use('vue-loader') - .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vue-loader')) - .tap(options => Object.assign(options, { - compiler: require('@dcloudio/uni-template-compiler'), - compilerOptions: { - quickapp: true, - preserveWhitespace: false - }, - hotReload: false, - cacheDirectory: false, - cacheIdentifier: false - })) + .loader(vueLoader.loader) + .tap(options => Object.assign(options, vueLoader.options({}, { + quickapp: true, + }))) config.module .rule('vue') diff --git a/packages/vue-cli-plugin-uni/lib/app-plus/index.js b/packages/vue-cli-plugin-uni/lib/app-plus/index.js index 1f92d8f6007b3d51bca8540c13a7ff83030b6fe8..d7020707f16e7c20b7313335ffb94cf254af6172 100644 --- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js +++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js @@ -7,6 +7,8 @@ const { getPlatformCompiler } = require('@dcloudio/uni-cli-shared') +const vueLoader = require('@dcloudio/uni-cli-shared/lib/vue-loader') + const { getGlobalUsingComponentsCode } = require('@dcloudio/uni-cli-shared/lib/pages') @@ -14,7 +16,6 @@ const { const WebpackUniAppPlugin = require('../../packages/webpack-uni-app-loader/plugin/index') const { - isUnaryTag, getPartialIdentifier } = require('../util') @@ -245,7 +246,6 @@ const v3 = { } const compilerOptions = { - isUnaryTag, preserveWhitespace: false, service: isAppService, view: isAppView @@ -254,23 +254,14 @@ const v3 = { // disable vue cache-loader webpackConfig.module .rule('vue') - .test([/\.vue$/, /\.nvue$/]) + .test(vueLoader.test) .use('vue-loader') // service 层移除 style 节点,view 层返回固定 script - .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vue-loader')) - .tap(options => Object.assign(options, { + .loader(vueLoader.loader) + .tap(options => Object.assign(options, vueLoader.options({ isAppService, - isAppView, - compiler: getPlatformCompiler(), - compilerOptions - }, cacheConfig)) + isAppView + }, compilerOptions), cacheConfig)) .end() - // .use('uniapp-custom-block-loader') - // .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader')) - // .options({ - // isAppService, - // isAppView, - // compiler: getPlatformCompiler() - // }) // 是否启用 cache if (process.env.UNI_USING_CACHE) { diff --git a/packages/vue-cli-plugin-uni/lib/h5/index.js b/packages/vue-cli-plugin-uni/lib/h5/index.js index a00b7d3edc562798918617d2c663215792fbe6d3..7bf377cbbde55ba5dd937e645479144e630a9be2 100644 --- a/packages/vue-cli-plugin-uni/lib/h5/index.js +++ b/packages/vue-cli-plugin-uni/lib/h5/index.js @@ -180,7 +180,14 @@ global.onAppShow = function(){}; webpackConfig.plugins.delete('preload-index') } - modifyVueLoader(webpackConfig, require('./compiler-options'), api) + modifyVueLoader(webpackConfig, { + isH5: true, + hotReload: true, + transformAssetUrls: { + 'v-uni-image': ['src'], + 'v-uni-cover-image': ['src'] + } + }, require('./compiler-options'), api) if (process.env.NODE_ENV === 'production') { require('./cssnano-options')(webpackConfig) diff --git a/packages/vue-cli-plugin-uni/lib/mp.js b/packages/vue-cli-plugin-uni/lib/mp.js index d20f5f40a00dd4427abea3b985fc81910c0e55d9..a0fb30eb26ab4b955dda3d98e02f64c635c4a0fe 100644 --- a/packages/vue-cli-plugin-uni/lib/mp.js +++ b/packages/vue-cli-plugin-uni/lib/mp.js @@ -17,11 +17,7 @@ const { } = require('./cache-loader') function createUniMPPlugin () { - if (process.env.UNI_USING_COMPONENTS) { - const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new') - return new WebpackUniMPPlugin() - } - const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin') + const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new') return new WebpackUniMPPlugin() } @@ -181,7 +177,7 @@ module.exports = { const compilerOptions = process.env.UNI_USING_COMPONENTS ? {} : require('./mp-compiler-options') - modifyVueLoader(webpackConfig, compilerOptions, api) + modifyVueLoader(webpackConfig, {}, compilerOptions, api) const styleExt = getPlatformExts().style diff --git a/packages/vue-cli-plugin-uni/lib/vue-loader.js b/packages/vue-cli-plugin-uni/lib/vue-loader.js index b58ea411c6103b466b37c8a391e6f0f61a48fd4e..0a560d0eef4fd27776bf3b28c759289e32be4501 100644 --- a/packages/vue-cli-plugin-uni/lib/vue-loader.js +++ b/packages/vue-cli-plugin-uni/lib/vue-loader.js @@ -1,13 +1,10 @@ -const { - getPlatformCompiler -} = require('@dcloudio/uni-cli-shared') +const vueLoader = require('@dcloudio/uni-cli-shared/lib/vue-loader') const { - isUnaryTag, getPartialIdentifier } = require('./util') -module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api) { +module.exports = function modifyVueLoader (webpackConfig, loaderOptions, compilerOptions, api) { // vue-loader options const cacheConfig = { @@ -24,23 +21,11 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api) webpackConfig.module .rule('vue') - .test([/\.vue$/, /\.nvue$/]) + .test(vueLoader.test) .use('vue-loader') - .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vue-loader')) - .tap(options => Object.assign(options, { - isH5: process.env.UNI_PLATFORM === 'h5', - compiler: getPlatformCompiler(), - compilerOptions: Object.assign({ - isUnaryTag, - preserveWhitespace: false - }, compilerOptions) - }, cacheConfig)) + .loader(vueLoader.loader) + .tap(options => Object.assign(options, vueLoader.options(loaderOptions, compilerOptions), cacheConfig)) .end() - // .use('uniapp-custom-block-loader') - // .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader')) - // .options({ - // compiler: getPlatformCompiler() - // }) // h5 框架需要使用 scoped 样式,其他平台编译时识别是否 nvue 文件且注入 flex 相关样式 if (process.env.UNI_PLATFORM === 'h5') { diff --git a/packages/webpack-uni-mp-loader/lib/plugin/compile-to-template.js b/packages/webpack-uni-mp-loader/lib/plugin/compile-to-template.bak similarity index 100% rename from packages/webpack-uni-mp-loader/lib/plugin/compile-to-template.js rename to packages/webpack-uni-mp-loader/lib/plugin/compile-to-template.bak diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-components-wxml.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-components-wxml.bak similarity index 100% rename from packages/webpack-uni-mp-loader/lib/plugin/generate-components-wxml.js rename to packages/webpack-uni-mp-loader/lib/plugin/generate-components-wxml.bak diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-pages-wxml.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-pages-wxml.bak similarity index 100% rename from packages/webpack-uni-mp-loader/lib/plugin/generate-pages-wxml.js rename to packages/webpack-uni-mp-loader/lib/plugin/generate-pages-wxml.bak diff --git a/packages/webpack-uni-mp-loader/lib/plugin/index.js b/packages/webpack-uni-mp-loader/lib/plugin/index.bak similarity index 100% rename from packages/webpack-uni-mp-loader/lib/plugin/index.js rename to packages/webpack-uni-mp-loader/lib/plugin/index.bak