Authored by 毕凯

gulp 修改

/*# sourceMappingURL=index.css.map */
... ...
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.css","sourceRoot":"/source/","sourcesContent":[]}
\ No newline at end of file
... ...
webpackJsonp([0,1],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports) {
"use strict";
/***/ }
]);
\ No newline at end of file
... ...
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ var parentJsonpFunction = window["webpackJsonp"];
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, callbacks = [];
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId])
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
/******/ while(callbacks.length)
/******/ callbacks.shift().call(null, __webpack_require__);
/******/ if(moreModules[0]) {
/******/ installedModules[0] = 0;
/******/ return __webpack_require__(0);
/******/ }
/******/ };
/******/ // The module cache
/******/ var installedModules = {};
/******/ // object to store loaded and loading chunks
/******/ // "0" means "already loaded"
/******/ // Array means "loading", array contains callbacks
/******/ var installedChunks = {
/******/ 1:0
/******/ };
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
/******/ // "0" is the signal for "already loaded"
/******/ if(installedChunks[chunkId] === 0)
/******/ return callback.call(null, __webpack_require__);
/******/ // an array means "currently loading".
/******/ if(installedChunks[chunkId] !== undefined) {
/******/ installedChunks[chunkId].push(callback);
/******/ } else {
/******/ // start chunk loading
/******/ installedChunks[chunkId] = [callback];
/******/ var head = document.getElementsByTagName('head')[0];
/******/ var script = document.createElement('script');
/******/ script.type = 'text/javascript';
/******/ script.charset = 'utf-8';
/******/ script.async = true;
/******/ script.src = __webpack_require__.p + "" + chunkId + "." + ({"0":"index"}[chunkId]||chunkId) + ".js";
/******/ head.appendChild(script);
/******/ }
/******/ };
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ })
/************************************************************************/
/******/ ([]);
\ No newline at end of file
... ...
... ... @@ -5,7 +5,10 @@
*/
var gulp = require('gulp');
var webpack = require('webpack-stream');
var path = require('path');
var webpack = require('webpack');
var gutil = require('gulp-util');
var WebpackDevServer = require('webpack-dev-server');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
... ... @@ -15,7 +18,7 @@ var named = require('vinyl-named');
var cp = require('child_process');
var fs = require('fs');
var config = JSON.parse(fs.readFileSync('./package.json').toString());
var config = require('./package');
var root = `dist/${config.name}/`;
var distDir = {
... ... @@ -25,7 +28,10 @@ var distDir = {
font: root + 'assets/font'
};
gulp.task('default', ['postcss-dev', 'postcss-watch', 'js']);
//webpack config
var webpackConfig = require('./webpack.config.js');
gulp.task('default', ['postcss-dev', 'postcss-watch', 'webpack-server']);
//根据环境变量生成postcss插件配置
... ... @@ -86,6 +92,8 @@ function postcssEnvPlugin(env) {
require('postcss-sprites').default(sprites),
require('postcss-calc'),
require('postcss-opacity'),
require('stylelint')(),
require('postcss-reporter')({ clearMessages: true }),
//可选
require('postcss-use')({
... ... @@ -126,9 +134,21 @@ gulp.task('postcss-pro', ['assets'], function() {
});
gulp.task('js', function() {
var proConfig = Object.assign({}, webpackConfig);
proConfig.plugins.concat(
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("production")
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
return gulp.src('./index.js')
.pipe(named())
.pipe(webpack(require('./webpack.config.js')))
.pipe(webpack(proConfig))
.pipe(gulp.dest(distDir.js))
});
... ... @@ -156,3 +176,27 @@ gulp.task('server', () => {
}
});
});
//webpack server
gulp.task('webpack-server', (cb) => {
var devConfig = Object.assign({}, webpackConfig, {
entry: './index.js',
output: {
path: path.resolve(__dirname, '/build'),
filename: '[name].js'
},
plugins: []//TODO: 没理清commonChunkPlugin加载后文件访问问题??
});
new WebpackDevServer(webpack(devConfig), {
inline: true,
stats: {
clors: true
}
}).listen(8002, 'localhost', (err) => {
if (err) {
throw new gutil.PluginError('webpack-server-server', err);
}
gutil.log('[webpack-server]', 'http://localhost:8002/');
});
});
... ...
... ... @@ -15,7 +15,7 @@
<link rel="dns-prefetch" href="//img12.static.yhbimg.com">
<link rel="dns-prefetch" href="//img13.static.yhbimg.com">
{{#if devEnv}}
<link rel="stylesheet" href="{{assetsUrl}}/{{module}}/dist/css/index.css">
<link rel="stylesheet" href="{{assetsUrl}}/{{module}}/css/index.css">
{{^}}
<link rel="stylesheet" href="{{assetsUrl}}/{{module}}/{{version}}/index.css">
{{/if}}
... ...