Skip to content

Commit

Permalink
优化打包流程‘
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoranWong committed Oct 9, 2020
1 parent e484547 commit f63aa98
Show file tree
Hide file tree
Showing 8 changed files with 2,901 additions and 232 deletions.
2 changes: 1 addition & 1 deletion build/tool-config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function loadConfig (configPath, distConfigPath) {
}

ToolConfigLoader.prototype.apply = compiler => {
console.log(compiler);
// console.log(compiler);
}

module.exports = ToolConfigLoader;
Expand Down
10 changes: 5 additions & 5 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ module.exports = {
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[ext]')
}
loader: ['url-loader?limit=10000&name='+utils.assetsPath('img/[name].[ext]'), 'image-webpack-loader'],
// options: {
// limit: 10000,
// name: utils.assetsPath('img/[name].[ext]')
// }
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
Expand Down
7 changes: 6 additions & 1 deletion build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const ToolConfigLoader = require('./tool-config-loader');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

// add hot-reload related code to entry chunks
// Object.keys(baseWebpackConfig.entry).forEach(function (name) {
Expand Down Expand Up @@ -79,7 +80,11 @@ var webpackConfig = merge(baseWebpackConfig, {
// inject: true
// }),
new FriendlyErrorsPlugin(),
new ToolConfigLoader('dev')
new ToolConfigLoader('dev'),
new BundleAnalyzerPlugin({
analyzerPort: 9800,
openAnalyzer: false
})
]
})

Expand Down
19 changes: 11 additions & 8 deletions build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,37 @@ var webpackConfig = merge(baseWebpackConfig, {
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf('node_modules') >= 0
(module.resource.indexOf('node_modules') >= 0
|| module.resource.indexOf('iview') >= 0
|| module.resource.indexOf('jssdk') >= 0)
) || count > 2
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'common/manifest',
chunks: ['common/vendor0', 'common/vendor1', 'common/vendor2']
}),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'common/manifest',
// chunks: ['common/vendor0', 'common/vendor1', 'common/vendor2']
// }),
new ToolConfigLoader('prod')
]
})

if (config.build.productionGzip) {
console.log('------- compression --------')
var CompressionWebpackPlugin = require('compression-webpack-plugin')

webpackConfig.plugins.push(
new CompressionWebpackPlugin({
asset: '[path].gz[query]',
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' +
config.build.productionGzipExtensions.join('|') +
')$'
),
threshold: 10240,
minRatio: 0.8
threshold: 1024,
minRatio: 0.6
})
)
}
Expand Down
4 changes: 2 additions & 2 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ module.exports = {
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: '',
assetsPublicPath: '/',
productionSourceMap: false,
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzip: true,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
Expand Down
Loading

0 comments on commit f63aa98

Please sign in to comment.