-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwebpack.config.js
147 lines (136 loc) · 4.35 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
141
142
143
144
145
146
147
/* eslint-disable import/no-commonjs */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const DashboardPlugin = require('webpack-dashboard/plugin');
const merge = require('webpack-merge');
const parts = require('./webpack.parts');
const PATHS = {
bundle: path.join(__dirname, 'src/charts/index.js'),
charts: path.join(__dirname, 'src/charts'),
lib: path.join(__dirname, 'lib'),
build: path.join(__dirname, 'dist'),
umd: path.join(__dirname, 'lib/umd'),
cjs: path.join(__dirname, 'lib/cjs'),
};
const CHARTS = {
Bar: `${PATHS.charts}/bar/Bar.js`,
Bullet: `${PATHS.charts}/bullet/Bullet.js`,
Donut: `${PATHS.charts}/donut/Donut.js`,
GroupedBar: `${PATHS.charts}/groupedBar/GroupedBar.js`,
Legend: `${PATHS.charts}/legend/Legend.js`,
Line: `${PATHS.charts}/line/Line.js`,
StackedArea: `${PATHS.charts}/stackedArea/StackedArea.js`,
StackedBar: `${PATHS.charts}/stackedBar/StackedBar.js`,
Sparkline: `${PATHS.charts}/sparkline/Sparkline.js`,
Step: `${PATHS.charts}/step/Step.js`,
Tooltip: `${PATHS.charts}/tooltip/Tooltip.js`,
};
// Configurations
const commonSplittedConfig = merge([
{
entry: CHARTS,
output: {
path: PATHS.lib,
filename: '[name].js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Webpack demo',
}),
],
externals: {
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
react: parts.externals().react,
'react-dom': parts.externals()['react-dom'],
},
},
parts.lintJavaScript({
include: PATHS.charts,
options: {
emitWarning: true,
},
}),
]);
const developmentConfig = merge([
parts.devServer({
host: process.env.HOST,
port: process.env.PORT,
}),
{
plugins: [
// If you require a missing module and then `npm install` it, you still have
// to restart the development server for Webpack to discover it. This plugin
// makes the discovery automatic so you don't have to restart.
// See https://github.com/facebookincubator/create-react-app/issues/186
new WatchMissingNodeModulesPlugin(path.resolve('node_modules')),
new DashboardPlugin({ port: process.env.PORT }),
],
output: {
devtoolModuleFilenameTemplate:
'webpack:///[absolute-resource-path]',
},
},
parts.babelLoader(),
parts.generateSourceMaps({ type: 'cheap-module-eval-source-map' }),
]);
const libraryUMDConfig = merge([
commonSplittedConfig,
{
output: {
path: PATHS.umd,
filename: '[name].js',
library: ['britecharts-react', '[name]'],
libraryTarget: 'umd',
globalObject: 'this',
},
externals: parts.externals(),
},
parts.babelLoader(),
parts.generateSourceMaps({ type: 'source-map' }),
]);
const libraryCJSConfig = merge([
commonSplittedConfig,
{
output: {
path: PATHS.cjs,
filename: '[name].js',
library: ['britecharts-react', '[name]'],
libraryTarget: 'commonjs2',
},
externals: parts.externals(),
},
parts.babelLoader(),
parts.generateSourceMaps({ type: 'source-map' }),
]);
const bundleConfig = merge([
{
entry: {
'britecharts-react': PATHS.bundle,
},
output: {
path: PATHS.build,
filename: 'britecharts-react.min.js',
library: ['britecharts-react'],
libraryTarget: 'umd',
globalObject: 'this',
},
},
parts.babelLoader(),
parts.generateSourceMaps({ type: 'source-map' }),
// parts.bundleTreeChart(),
parts.minifyJavaScript(),
parts.copy({
from: 'node_modules/britecharts/dist/css/britecharts.min.css',
to: 'britecharts-react.min.css',
}),
]);
module.exports = (env) => {
console.log('%%%%%%%% env', env);
if (env === 'production') {
return [libraryCJSConfig, libraryUMDConfig, bundleConfig];
}
return merge(commonSplittedConfig, developmentConfig);
};