Skip to content

Commit 08dd4d3

Browse files
author
Ken Berkeley
committed
improve prod build config
1 parent 526d338 commit 08dd4d3

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

build/config/PATHS.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
ROOT: ROOT, // 项目根目录
1616
BUILD: ROOT.join('build'), // 构建工具配置目录
1717
DIST: ROOT.join('dist'), // build 后输出目录
18+
DOCS: ROOT.join('docs'), // 文档
1819
MOCK: ROOT.join('mock'), // Mock Server 目录
1920
SRC: ROOT.join('src'), // 源码目录
2021
STATIC: ROOT.join('static') // 高度静态资源目录

build/prod.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
var fs = require('fs'),
1+
var fs = require('fs-extra'),
22
webpack = require('webpack'),
33
gulp = require('./gulpfile'),
44
PATHS = require('./config/PATHS'),
55
config = require('./webpack.prod.conf');
66

7+
fs.emptyDirSync(PATHS.DIST); // 清空 build 目录
8+
fs.copySync(PATHS.STATIC, PATHS.DIST.join('static')); // 复制高度静态资源
9+
fs.copySync(PATHS.DOCS.join('_book'), PATHS.DIST.join('docs')); // 复制文档
10+
711
webpack(config, function(err, stats) {
812
// show build info to console
913
console.log(stats.toString({ chunks: false, color: true }));

build/webpack.prod.conf.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var webpack = require('webpack'),
33
PATHS = require('./config/PATHS'),
44
config = require('./webpack.base.conf'),
55
HtmlWebpackPlugin = require('html-webpack-plugin'),
6-
CopyWebpackPlugin = require('copy-webpack-plugin'),
76
ExtractTextPlugin = require('extract-text-webpack-plugin'),
87
// SOURCE_MAP = true; // 大多数情况下用不到
98
SOURCE_MAP = false;
@@ -25,8 +24,6 @@ config.module.loaders.push({
2524
loader: ExtractTextPlugin.extract('style', 'css!sass')
2625
});
2726

28-
fs.emptyDirSync(PATHS.DIST); // 清空 build 目录
29-
3027
config.plugins.push(
3128
new webpack.optimize.DedupePlugin(),
3229
new webpack.optimize.OccurenceOrderPlugin(),
@@ -49,21 +46,7 @@ config.plugins.push(
4946
new HtmlWebpackPlugin({
5047
filename: '../index.html',
5148
template: PATHS.SRC.join('index.html')
52-
}),
53-
new CopyWebpackPlugin([ // 复制高度静态资源
54-
{
55-
context: PATHS.STATIC,
56-
from: '**/*',
57-
ignore: ['*.md']
58-
}
59-
]),
60-
new CopyWebpackPlugin([ // 复制文档
61-
{
62-
context: PATHS.ROOT.join('docs/_book'),
63-
from: '**/*',
64-
to: '../docs/'
65-
}
66-
])
49+
})
6750
);
6851

6952
module.exports = config;

dist/static/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
本目录放置高度静态且不经由 Webpack 处理的文件
2+
(例如需要全局引入的样式、脚本)
3+
其中 plugins/ 存放需要 Gulp 合并压缩打包的文件

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"browser-sync": "^2.11.1",
3333
"browser-sync-webpack-plugin": "^1.0.1",
3434
"connect-history-api-fallback": "^1.1.0",
35-
"copy-webpack-plugin": "^4.0.1",
3635
"cross-env": "^3.1.3",
3736
"css-loader": "^0.23.0",
3837
"eslint": "^1.10.3",

0 commit comments

Comments
 (0)