Last active
December 30, 2015 08:59
-
-
Save axross/27440c73903d702df253 to your computer and use it in GitHub Desktop.
gulp捨てられなかった
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const autoprefixer = require('gulp-autoprefixer'); | |
const cssnano = require('gulp-cssnano'); | |
const gulp = require('gulp'); | |
const gutil = require('gulp-util'); | |
const rename = require('gulp-rename'); | |
const sourcemaps = require('gulp-sourcemaps'); | |
const stylus = require('gulp-stylus'); | |
const uglify = require('gulp-uglify'); | |
const webpack = require('webpack'); | |
const webpackConfig = require('./webpack.config.js'); | |
let isWatching = false; | |
gulp.task('bundle:js', done => { | |
let isAlreadyFinished = false; | |
webpack(Object.assign({}, webpackConfig, { | |
watch: isWatching, | |
}), (err, stats) => { | |
if (err) throw new gutil.PluginError('webpack', err); | |
gutil.log('\n', stats.toString({ | |
version: false, | |
chunks: false, | |
colors: true, | |
})); | |
if (!isAlreadyFinished) { | |
done(); | |
isAlreadyFinished = true; | |
} | |
}); | |
}); | |
gulp.task('bundle:css', () => { | |
gulp.src('./client/app.styl') | |
.pipe(sourcemaps.init()) | |
.pipe(stylus()) | |
.pipe(autoprefixer()) | |
.pipe(cssnano()) | |
.pipe(rename('bundle.css')) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('./public')) | |
}); | |
gulp.task('bundle', ['bundle:css', 'bundle:js']); | |
gulp.task('watch-enable', () => isWatching = true); | |
gulp.task('bundle-watch', ['watch-enable', 'bundle'], () => { | |
gulp.watch('./client/**/*.styl', ['bundle:css']); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpack = require('webpack'); | |
module.exports = { | |
entry: { | |
'bundle.js': './client/app.js', | |
'lib.js': './client/lib.js', | |
}, | |
output: { | |
path: './public', | |
filename: '[name]', | |
}, | |
externals: { | |
'react': 'window.__lib__["react"]', | |
'react-dom': 'window.__lib__["react-dom"]', | |
'react-router': 'window.__lib__["react-router"]', | |
'history': 'window.__lib__["history"]', | |
'redux': 'window.__lib__["redux"]', | |
'react-redux': 'window.__lib__["react-redux"]', | |
}, | |
devtool: 'source-map', | |
module: { | |
loaders: [ | |
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' } | |
] | |
}, | |
plugins: [ | |
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment