forked from vmware-archive/react-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
140 lines (125 loc) · 2.77 KB
/
webpack.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
// Project settings
let project = 'react-console';
let library = 'Console';
let externals = {
"react": "React",
"react-dom": "ReactDOM",
};
// Build system
let webpack = require('webpack');
let FailPlugin = require('webpack-fail-plugin');
let ExtractTextPlugin = require('extract-text-webpack-plugin');
let ArchivePlugin = require('webpack-archive-plugin');
let nodeExternals = require('webpack-node-externals');
let options = {
dev: process.argv.indexOf('--dev') != -1,
dist: process.argv.indexOf('--dist') != -1,
lib: process.argv.indexOf('--lib') != -1,
default: process.argv.indexOf('--dev') == -1
&& process.argv.indexOf('--dist') == -1
&& process.argv.indexOf('--lib') == -1,
};
let base = {
context: __dirname + "/src",
entry: './' + project + '.tsx',
module: {
loaders: [
{
test: /\.tsx?$/,
loader: "ts-loader",
},
{
test: /\.s?css$/,
loader: ExtractTextPlugin.extract("css-loader?sourceMap!sass-loader?sourceMap"),
},
],
preLoaders: [
{
test: /\.(css|js)$/,
loader: "source-map-loader",
}
],
},
devtool: 'source-map',
};
let production_plugins = [
FailPlugin,
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
]
let dist = Object.assign({},base, {
output: {
path: __dirname + '/dist/dist',
filename: project + '.js',
library: library,
libraryTarget: "var",
},
externals: externals,
plugins: [
FailPlugin,
new ArchivePlugin(),
new ExtractTextPlugin(project + '.css'),
],
});
let dist_min = Object.assign({},dist, {
output: {
path: __dirname + '/dist/dist-min',
filename: project + '.min.js',
library: library,
libraryTarget: "var",
},
plugins: [
FailPlugin,
new ExtractTextPlugin(project + '.min.css'),
new ArchivePlugin(),
...production_plugins,
],
});
let libexternals = {}
for(let key in externals) {
if(externals.hasOwnProperty(key)) {
libexternals[key] = true;
}
}
let lib = Object.assign({},dist, {
output: {
path: __dirname + '/lib',
filename: project + '.js',
library: library,
libraryTarget: "commonjs2",
},
externals: libexternals,
plugins: [
FailPlugin,
new ExtractTextPlugin(project + '.css'),
],
});
let development = Object.assign({},base, {
entry: '../dev/dev.tsx',
output: {
path: __dirname + '/dev/dist',
filename: project + '.dev.js',
library: "Dev",
libraryTarget: "var",
},
plugins: [
FailPlugin,
new ExtractTextPlugin(project + '.dev.css'),
],
});
let targets = [];
if(options.dev || options.default) {
targets.push(development);
}
if(options.dist || options.default) {
targets.push(dist, dist_min);
}
if(options.lib || options.default) {
targets.push(lib);
}
module.exports = targets;