Skip to content

Commit

Permalink
chore(gulpfile, webpack): use webpack to uglify js
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Feb 4, 2018
1 parent 827bb3f commit e9363f6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
14 changes: 7 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const gulp = require('gulp'),
webpack = require('webpack'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
browserSync = require('browser-sync').create()

Expand Down Expand Up @@ -58,10 +57,11 @@ gulp.task('dev', ['webpack', 'sass'], function () {

/* ========== bulid ========== */

// uglify
gulp.task('uglify-js', ['webpack'], function () {
return gulp.src('./source/scripts/main.js').pipe(uglify())
.pipe(gulp.dest('./source/scripts/'))
// webpack-prod
gulp.task('webpack-prod', function (cb) {
webpack(require('./webpack.prod.js'), function (err) {
if (err) return cb(err)
cb()
})
})

gulp.task('build', ['sass', 'uglify-js'])
gulp.task('build', ['sass', 'webpack-prod'])
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"eslint-config-alloy": "^1.4.0",
"gulp": "^3.9.1",
"gulp-sass": "^3.1.0",
"gulp-uglify": "^3.0.0",
"webpack": "^3.10.0"
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^3.10.0",
"webpack-merge": "^4.1.1"
},
"dependencies": {
"anchor-js": "^4.1.0",
Expand Down
5 changes: 2 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const webpack = require('webpack')
const path = require('path')


module.exports = {
entry: './src/js/main.js', // 已多次提及的唯一入口文件
output: {
Expand All @@ -23,4 +21,5 @@ module.exports = {
},
}]
}
}
}

15 changes: 15 additions & 0 deletions webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const webpack = require('webpack')
const merge = require('webpack-merge')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const config = require('./webpack.config.js')

module.exports = merge(config, {
plugins: [
new UglifyJSPlugin({
sourceMap: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
})

0 comments on commit e9363f6

Please sign in to comment.