Skip to content

Commit

Permalink
feat: 添加编译缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
kodomozz committed Oct 19, 2020
1 parent c676897 commit 623071c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/chameleon-tool/configs/getCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const {getBabelPath, getExcludeBabelPath, getGlobalCheckWhiteList, getFreePort} = require('./utils');
const {getBabelPath, getExcludeBabelPath, getGlobalCheckWhiteList, getFreePort, addCahceLoader} = require('./utils');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const ChameleonWebpackPlugin = require('chameleon-webpack-plugin')
Expand Down Expand Up @@ -162,6 +162,9 @@ module.exports = function (options) {
})
]
}
if (options.cache) {
addCahceLoader(commonConfig, type);
}
if (chameleonConfig.enableGlobalCheck === true) {
commonConfig.plugins.push(
new WebpackCheckPlugin({
Expand Down
3 changes: 3 additions & 0 deletions packages/chameleon-tool/configs/getMiniAppCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ module.exports = function (options) {
// 组件导出,修改jsonpFunction
commonConfig.output.jsonpFunction = getJsonpFunction(root);
}
if (options.cache) {
utils.addCahceLoader(commonConfig, type);
}


return merge(getCommonConfig(options), commonConfig);
Expand Down
2 changes: 1 addition & 1 deletion packages/chameleon-tool/configs/getWebBuildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function (options) {
new CleanWebpackPlugin(['./*'], {root: outputPath, verbose: false})
]
}

const obj = getWebCommonConfig(options);

return merge(getWebCommonConfig(options), buildConfig)
}
3 changes: 3 additions & 0 deletions packages/chameleon-tool/configs/getWebCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ module.exports = function (options) {
}
)
}
if (options.cache) {
utils.addCahceLoader(commonConfig, 'web');
}
return merge(getCommonConfig(options), commonConfig);

}
Expand Down
5 changes: 3 additions & 2 deletions packages/chameleon-tool/configs/getWeexCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ module.exports = function (options) {
}
)
}
if (options.cache) {
utils.addCahceLoader(commonConfig, 'weex');
}
return merge(getCommonConfig(options), commonConfig);


}


20 changes: 20 additions & 0 deletions packages/chameleon-tool/configs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,23 @@ exports.getFreePort = function () {
}
}

exports.addCahceLoader = (config, type) => {
const cacheUseLoader = {
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve(process.cwd(), `node_modules/.cache/cache-loader/cache_${type}`)
}
}
const testee = ['.interface', '.cml', '.vue', '.js'];

config.module.rules.forEach(rule => {
testee.some(ext => {
const isRegExp = Object.prototype.toString.call(rule.test) === '[object RegExp]';

if (isRegExp && rule.test.test(ext)) {
return rule.use && rule.use.unshift(cacheUseLoader);
}
})
})
}

1 change: 1 addition & 0 deletions packages/chameleon-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"babel-preset-flow": "6.23.0",
"babel-preset-stage-0": "6.24.1",
"body-parser": "^1.18.3",
"cache-loader": "^4.1.0",
"chalk": "^2.4.2",
"chameleon-css-loader": "^1.0.8-alpah.1",
"chameleon-dev-proxy": "^1.0.8-alpah.1",
Expand Down

0 comments on commit 623071c

Please sign in to comment.