Skip to content

Commit

Permalink
Add disableCompress option
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 5, 2017
1 parent 0c36158 commit 40c0526
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
36 changes: 26 additions & 10 deletions bin/vue-build
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ program
.option('-o, --open', 'Open browser')
.option('--proxy [url]', 'Proxy API request')
.option('--lib [libraryName]', 'Distribute component in UMD format')
.option('--disable-compress', 'Disable compress when building in production mode')
.parse(process.argv)

var args = program.args
Expand Down Expand Up @@ -75,7 +76,8 @@ var options = merge({
proxy: program.proxy,
production: program.production,
lib: program.lib,
watch: program.watch
watch: program.watch,
disableCompress: program.disableCompress
})

function help () {
Expand Down Expand Up @@ -248,23 +250,37 @@ if (isYarn(__dirname)) {
}

if (production) {
webpackConfig.devtool = 'source-map'
webpackConfig.plugins.push(
new ProgressPlugin(),
new webpack.optimize.UglifyJsPlugin({
new webpack.LoaderOptionsPlugin({
minimize: !options.disableCompress
}),
new ExtractTextPlugin(filenames.css)
)

if (options.disableCompress) {
webpackConfig.devtool = false
} else {
webpackConfig.devtool = 'source-map'
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compressor: {
warnings: false
warnings: false,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
negate_iife: false
},
output: {
comments: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new ExtractTextPlugin(filenames.css)
)
}))
}
} else {
if (!options.watch) {
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin())
Expand Down
6 changes: 6 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ Set custom filename for `js` `css` `static` files:
}
```

#### disableCompress

Type: `boolean`

In production mode, all generated files will be compressed and produce sourcemaps file. You can use `--disableCompress` to disable this behavior.

#### proxy

Type: `string`, `Object`
Expand Down
13 changes: 9 additions & 4 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ module.exports = function (webpackConfig, options) {
}))
console.log(`\n${chalk.bgGreen.black(' SUCCESS ')} Compiled successfully.\n`)
if (!watch) {
console.log(`The ${chalk.cyan(options.dist)} folder is ready to be deployed.`)
console.log(`You may also serve it locally with a static server:\n`)
console.log(` ${chalk.yellow('npm')} i -g serve`)
console.log(` ${chalk.yellow('serve')} ${options.dist} --single\n`)
if (options.lib) {
console.log(`The ${chalk.cyan(options.dist)} folder is ready to be published.`)
console.log(`Make sure you have correctly set ${chalk.cyan('package.json')}\n`)
} else {
console.log(`The ${chalk.cyan(options.dist)} folder is ready to be deployed.`)
console.log(`You may also serve it locally with a static server:\n`)
console.log(` ${chalk.yellow('npm')} i -g serve`)
console.log(` ${chalk.yellow('serve')} ${options.dist}\n`)
}
}
}
}

0 comments on commit 40c0526

Please sign in to comment.