-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtdtool.config.js
105 lines (97 loc) · 2.59 KB
/
tdtool.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const path = require('path');
const pkg = require('./package.json');
const webpack = require('webpack');
const Config = require('tdtool').Config;
const TARGET = process.env.npm_lifecycle_event;
const isDebug = TARGET.indexOf('release') == -1;
const config = require('./config.json');
const release = isDebug ? config.dev : config.release;
const clientConfig = new Config({
entry: {
[pkg.name]: './src/client',
vendor1: ['react', 'react-dom', 'mobx', 'mobx-react', 'react-router'],
vendor2: ['moment', 'moment/locale/zh-cn']
},
sourceMap: true,
filename: '[name].js',
minimize: !isDebug,
externals: {
jquery: 'window.$'
},
extends: [['react', {
plugins: [
["import", { libraryName: "td-ui", style: true }]
]
}], ['less', {
extractCss: {
filename: '[name].css',
allChunks: true
}
}]],
env: {
'process.env.NODE_ENV': isDebug ? '"development"': '"production"',
__DEV__: isDebug,
'process.env.BROWSER': true
}
});
clientConfig.add(
'plugin.Common',
new webpack.optimize.CommonsChunkPlugin({
name: ['vendor2', 'vendor1', 'minifest'],
filename: '[name].js',
})
);
const AssetsPlugin = require('assets-webpack-plugin');
clientConfig.add(
'plugin.AssetsPlugin',
new AssetsPlugin({
path: isDebug ? './dist' : './build/server',
filename: 'assets.json',
prettyPrint: true,
})
);
if (!isDebug) {
clientConfig.add('output.path', path.join(release, 'client'));
clientConfig.add('output.publicPath', '/');
clientConfig.add('output.chunkFilename', '[name].chunk.js');
// module.exports = clientConfig.resolve();
} else {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
clientConfig.add(
'plugin.BundleAnalyzerPlugin',
new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerHost: '127.0.0.1',
analyzerPort: 4875,
reportFilename: 'report.html',
openAnalyzer: true,
generateStatsFile: true,
statsFilename: 'analyseStats.json',
statsOptions: null,
logLevel: 'info',
})
);
}
const serverConfig = new Config({
entry: './src/server',
target: 'node',
filename: 'server.js',
sourceMap: true,
devServer: true,
externals: [/^\.\/assets\.json$/],
extends: [['react', {
plugins: [
["import", { libraryName: "td-ui", style: true }]
]
}], ['less', {
target: 'node'
}]],
env: {
__DEV__: isDebug,
'process.env.BROWSER': false
}
});
if (!isDebug) {
serverConfig.add('output.path', path.join(release, 'server'));
}
module.exports = [clientConfig.resolve(), serverConfig.resolve()];