提交 d6ba5bbe 编写于 作者: fxy060608's avatar fxy060608

feat(v3): add cache

...@@ -7,7 +7,8 @@ const { ...@@ -7,7 +7,8 @@ const {
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const { const {
isUnaryTag isUnaryTag,
getPartialIdentifier
} = require('../util') } = require('../util')
function getProvides () { function getProvides () {
...@@ -79,8 +80,8 @@ const v3 = { ...@@ -79,8 +80,8 @@ const v3 = {
externals: { externals: {
vue: 'Vue' vue: 'Vue'
}, },
entry () { entry () {
return entry return entry
}, },
output: { output: {
filename: '[name].js', filename: '[name].js',
...@@ -127,18 +128,30 @@ const v3 = { ...@@ -127,18 +128,30 @@ const v3 = {
] ]
} }
}, },
chainWebpack (webpackConfig, vueOptions) { chainWebpack (webpackConfig, vueOptions, api) {
webpackConfig.entryPoints.delete('app') webpackConfig.entryPoints.delete('app')
const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service'] const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service']
const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view'] const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view']
const compilerOptions = { const cacheConfig = {
cacheDirectory: false,
cacheIdentifier: false
}
if (process.env.UNI_USING_CACHE) {
Object.assign(cacheConfig, api.genCacheConfig(
'vue-template-compiler/' + process.env.UNI_PLATFORM,
getPartialIdentifier()
))
}
const compilerOptions = Object.assign({
isUnaryTag, isUnaryTag,
preserveWhitespace: false, preserveWhitespace: false,
service: isAppService, service: isAppService,
view: isAppView view: isAppView
} }, cacheConfig)
// disable vue cache-loader // disable vue cache-loader
webpackConfig.module webpackConfig.module
...@@ -150,20 +163,30 @@ const v3 = { ...@@ -150,20 +163,30 @@ const v3 = {
isAppService, isAppService,
isAppView, isAppView,
compiler: getPlatformCompiler(), compiler: getPlatformCompiler(),
compilerOptions, compilerOptions
cacheDirectory: false,
cacheIdentifier: false
})) }))
.end()
.use('uniapp-custom-block-loader')
.loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader'))
.options({
compiler: getPlatformCompiler()
})
.end()
.uses
.delete('cache-loader')
.end() .end()
.use('uniapp-custom-block-loader')
.loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader'))
.options({
compiler: getPlatformCompiler()
})
// 是否启用 cache
if (process.env.UNI_USING_CACHE) {
webpackConfig.module
.rule('vue')
.use('cache-loader')
.tap(options => Object.assign(options, api.genCacheConfig(
'vue-loader/' + process.env.UNI_PLATFORM,
getPartialIdentifier()
)))
} else {
webpackConfig.module
.rule('vue')
.uses
.delete('cache-loader')
}
if (isAppView) { if (isAppView) {
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
......
...@@ -105,7 +105,7 @@ module.exports = { ...@@ -105,7 +105,7 @@ module.exports = {
}, { }, {
resourceQuery: /vue&type=template/, resourceQuery: /vue&type=template/,
use: [{ use: [{
loader: resolve('packages/h5-vue-template-loader') loader: resolve('packages/webpack-uni-app-loader/filter-modules-template.js')
}] }]
}, { }, {
resourceQuery: [/lang=wxs/, /blockType=wxs/], resourceQuery: [/lang=wxs/, /blockType=wxs/],
......
...@@ -14,7 +14,6 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api) ...@@ -14,7 +14,6 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api)
cacheDirectory: false, cacheDirectory: false,
cacheIdentifier: false cacheIdentifier: false
} }
const partialIdentifier = {}
if (process.env.UNI_USING_CACHE) { if (process.env.UNI_USING_CACHE) {
Object.assign(cacheConfig, api.genCacheConfig( Object.assign(cacheConfig, api.genCacheConfig(
...@@ -60,7 +59,7 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api) ...@@ -60,7 +59,7 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api)
.use('cache-loader') .use('cache-loader')
.tap(options => Object.assign(options, api.genCacheConfig( .tap(options => Object.assign(options, api.genCacheConfig(
'vue-loader/' + process.env.UNI_PLATFORM, 'vue-loader/' + process.env.UNI_PLATFORM,
partialIdentifier getPartialIdentifier()
))) )))
} else { } else {
webpackConfig.module webpackConfig.module
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册