Skip to content

Commit 5db723b

Browse files
committed
update build config
1 parent 605f80d commit 5db723b

File tree

6 files changed

+242
-3
lines changed

6 files changed

+242
-3
lines changed

build/task/gulp.webpack.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ var gulp = require('gulp')
22
var rimraf = require('rimraf')
33
var webpack = require('webpack')
44
var webpackConfig = require('../webpack.dev.js')
5+
var buildConfig = require('../webpack.build.js')
56
var WebpackDevServer = require("webpack-dev-server")
67
var config = require('../../config')
78
var opn = require('opn')
89

910

1011
gulp.task('webpack:clean',function (cb) {
11-
rimraf('./static',cb)
12+
rimraf('./static',function() {
13+
rimraf('./dist',function () {
14+
cb()
15+
})
16+
})
17+
1218
})
1319

1420

@@ -25,6 +31,8 @@ gulp.task('dev:server',function (callback) {
2531
})
2632
})
2733

28-
gulp.task('build',function () {
29-
34+
gulp.task('build',['webpack:clean'],function (cb) {
35+
webpack(buildConfig,function () {
36+
cb()
37+
})
3038
})

build/webpack.build.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var path = require('path')
2+
var webpack = require('webpack')
3+
var webpackConfig = require('./webpack.config.js')
4+
var merge = require('webpack-merge')
5+
var config = require('../config')
6+
var utils = require('./utils.js')
7+
var ExtractTextPlugin = require('extract-text-webpack-plugin')
8+
var HtmlWebpackPlugin = require('html-webpack-plugin');
9+
10+
module.exports = merge(webpackConfig,{
11+
output: {
12+
path: config.build.path,
13+
publicPath: config.build.publicPath
14+
},
15+
module: {
16+
rules: utils.styleLoaders({
17+
sourceMap: config.build.cssSourceMap
18+
})
19+
},
20+
plugins: [
21+
new webpack.DefinePlugin({
22+
23+
}),
24+
new ExtractTextPlugin({
25+
filename: 'css/[name].[contenthash].css'
26+
}),
27+
new HtmlWebpackPlugin({
28+
inject: true
29+
}),
30+
// split vendor js into its own file
31+
new webpack.optimize.CommonsChunkPlugin({
32+
name: 'vendor',
33+
minChunks: function (module, count) {
34+
// any required modules inside node_modules are extracted to vendor
35+
return (
36+
module.resource &&
37+
/\.js$/.test(module.resource) &&
38+
module.resource.indexOf(
39+
path.join(__dirname, '../node_modules')
40+
) === 0
41+
)
42+
}
43+
}),
44+
// extract webpack runtime and module manifest to its own file in order to
45+
// prevent vendor hash from being updated whenever app bundle is updated
46+
new webpack.optimize.CommonsChunkPlugin({
47+
name: 'manifest',
48+
chunks: ['vendor']
49+
}),
50+
]
51+
})

config/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var path = require('path')
33
module.exports = {
44
build: {
55
env: 'production',
6+
path: path.resolve(__dirname,'../dist'),
7+
publicPath: '/',
68
cssSourceMap: false,
79
cssExtra: true
810
},

dist/index.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Webpack App</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="/js/manifest.js"></script><script type="text/javascript" src="/js/app.js"></script></body>
9+
</html>

dist/js/app.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
webpackJsonp([0],[
2+
/* 0 */
3+
/***/ (function(module, exports) {
4+
5+
function* helloWorldGenerator() {
6+
yield 'hello';
7+
yield 'world';
8+
return 'ending';
9+
}
10+
11+
var hw = helloWorldGenerator();
12+
console.log(hw.next());
13+
14+
/***/ }),
15+
/* 1 */
16+
/***/ (function(module, exports, __webpack_require__) {
17+
18+
module.exports = __webpack_require__(0);
19+
20+
21+
/***/ })
22+
],[1]);

dist/js/manifest.js

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // install a JSONP callback for chunk loading
3+
/******/ var parentJsonpFunction = window["webpackJsonp"];
4+
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {
5+
/******/ // add "moreModules" to the modules object,
6+
/******/ // then flag all "chunkIds" as loaded and fire callback
7+
/******/ var moduleId, chunkId, i = 0, resolves = [], result;
8+
/******/ for(;i < chunkIds.length; i++) {
9+
/******/ chunkId = chunkIds[i];
10+
/******/ if(installedChunks[chunkId])
11+
/******/ resolves.push(installedChunks[chunkId][0]);
12+
/******/ installedChunks[chunkId] = 0;
13+
/******/ }
14+
/******/ for(moduleId in moreModules) {
15+
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
16+
/******/ modules[moduleId] = moreModules[moduleId];
17+
/******/ }
18+
/******/ }
19+
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);
20+
/******/ while(resolves.length)
21+
/******/ resolves.shift()();
22+
/******/ if(executeModules) {
23+
/******/ for(i=0; i < executeModules.length; i++) {
24+
/******/ result = __webpack_require__(__webpack_require__.s = executeModules[i]);
25+
/******/ }
26+
/******/ }
27+
/******/ return result;
28+
/******/ };
29+
/******/
30+
/******/ // The module cache
31+
/******/ var installedModules = {};
32+
/******/
33+
/******/ // objects to store loaded and loading chunks
34+
/******/ var installedChunks = {
35+
/******/ 1: 0
36+
/******/ };
37+
/******/
38+
/******/ // The require function
39+
/******/ function __webpack_require__(moduleId) {
40+
/******/
41+
/******/ // Check if module is in cache
42+
/******/ if(installedModules[moduleId])
43+
/******/ return installedModules[moduleId].exports;
44+
/******/
45+
/******/ // Create a new module (and put it into the cache)
46+
/******/ var module = installedModules[moduleId] = {
47+
/******/ i: moduleId,
48+
/******/ l: false,
49+
/******/ exports: {}
50+
/******/ };
51+
/******/
52+
/******/ // Execute the module function
53+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
54+
/******/
55+
/******/ // Flag the module as loaded
56+
/******/ module.l = true;
57+
/******/
58+
/******/ // Return the exports of the module
59+
/******/ return module.exports;
60+
/******/ }
61+
/******/
62+
/******/ // This file contains only the entry chunk.
63+
/******/ // The chunk loading function for additional chunks
64+
/******/ __webpack_require__.e = function requireEnsure(chunkId) {
65+
/******/ if(installedChunks[chunkId] === 0)
66+
/******/ return Promise.resolve();
67+
/******/
68+
/******/ // a Promise means "currently loading".
69+
/******/ if(installedChunks[chunkId]) {
70+
/******/ return installedChunks[chunkId][2];
71+
/******/ }
72+
/******/
73+
/******/ // setup Promise in chunk cache
74+
/******/ var promise = new Promise(function(resolve, reject) {
75+
/******/ installedChunks[chunkId] = [resolve, reject];
76+
/******/ });
77+
/******/ installedChunks[chunkId][2] = promise;
78+
/******/
79+
/******/ // start chunk loading
80+
/******/ var head = document.getElementsByTagName('head')[0];
81+
/******/ var script = document.createElement('script');
82+
/******/ script.type = 'text/javascript';
83+
/******/ script.charset = 'utf-8';
84+
/******/ script.async = true;
85+
/******/ script.timeout = 120000;
86+
/******/
87+
/******/ if (__webpack_require__.nc) {
88+
/******/ script.setAttribute("nonce", __webpack_require__.nc);
89+
/******/ }
90+
/******/ script.src = __webpack_require__.p + "js/" + chunkId + ".js";
91+
/******/ var timeout = setTimeout(onScriptComplete, 120000);
92+
/******/ script.onerror = script.onload = onScriptComplete;
93+
/******/ function onScriptComplete() {
94+
/******/ // avoid mem leaks in IE.
95+
/******/ script.onerror = script.onload = null;
96+
/******/ clearTimeout(timeout);
97+
/******/ var chunk = installedChunks[chunkId];
98+
/******/ if(chunk !== 0) {
99+
/******/ if(chunk) chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));
100+
/******/ installedChunks[chunkId] = undefined;
101+
/******/ }
102+
/******/ };
103+
/******/ head.appendChild(script);
104+
/******/
105+
/******/ return promise;
106+
/******/ };
107+
/******/
108+
/******/ // expose the modules object (__webpack_modules__)
109+
/******/ __webpack_require__.m = modules;
110+
/******/
111+
/******/ // expose the module cache
112+
/******/ __webpack_require__.c = installedModules;
113+
/******/
114+
/******/ // identity function for calling harmony imports with the correct context
115+
/******/ __webpack_require__.i = function(value) { return value; };
116+
/******/
117+
/******/ // define getter function for harmony exports
118+
/******/ __webpack_require__.d = function(exports, name, getter) {
119+
/******/ if(!__webpack_require__.o(exports, name)) {
120+
/******/ Object.defineProperty(exports, name, {
121+
/******/ configurable: false,
122+
/******/ enumerable: true,
123+
/******/ get: getter
124+
/******/ });
125+
/******/ }
126+
/******/ };
127+
/******/
128+
/******/ // getDefaultExport function for compatibility with non-harmony modules
129+
/******/ __webpack_require__.n = function(module) {
130+
/******/ var getter = module && module.__esModule ?
131+
/******/ function getDefault() { return module['default']; } :
132+
/******/ function getModuleExports() { return module; };
133+
/******/ __webpack_require__.d(getter, 'a', getter);
134+
/******/ return getter;
135+
/******/ };
136+
/******/
137+
/******/ // Object.prototype.hasOwnProperty.call
138+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
139+
/******/
140+
/******/ // __webpack_public_path__
141+
/******/ __webpack_require__.p = "/";
142+
/******/
143+
/******/ // on error function for async loading
144+
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
145+
/******/ })
146+
/************************************************************************/
147+
/******/ ([]);

0 commit comments

Comments
 (0)