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

feat(v3): add cache

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