-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.js
206 lines (191 loc) · 4.99 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const webpack = require('webpack');
const path = require('path');
// variables
const IS_PROD_MIN = process.env.NODE_ENV === "minify";
const IS_PROD = process.env.NODE_ENV === "production" || IS_PROD_MIN;
const IS_ANALYZE = process.env.NODE_ENV === "analyze";
const OUT_DIR = path.join(__dirname, './dist');
// plugins
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackMerge = require('webpack-merge');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const DtsBundlePlugin = require('./dtsBundlePlugin');
const cssFileName = IS_PROD_MIN ? "[name].min.css" : "[name].css";
const extractSass = new ExtractTextPlugin({
filename: cssFileName,
allChunks: true
});
const base = {
entry: {
sample: './sampleApp/sample',
OneNotePicker: './src/oneNotePicker',
OneNoteApiDataProvider: './src/providers/oneNoteApiDataProvider',
OneNoteItemUtils: './src/oneNoteDataStructures/oneNoteItemUtils'
},
output: {
path: OUT_DIR,
publicPath: '/dist/',
filename: '[name].js',
library: 'OneNotePicker',
libraryTarget: 'umd',
umdNamedDefine: true
},
target: 'web',
resolve: {
extensions: ['.js', '.ts', '.tsx'],
},
devtool: 'cheap-module-eval-source-map',
module: {
loaders: [
// .ts, .tsx
{
test: /\.tsx?$/,
use: IS_PROD ? 'ts-loader' : ['react-hot-loader', 'ts-loader']
},
{
test: /\.css/,
use: extractSass.extract({
use: [
{
loader: `css-loader?importLoaders=1&minimize=${IS_PROD_MIN}!postcss-loader`
}
],
fallback: 'style-loader'
})
},
{
test: /\.sass$/,
use: extractSass.extract({
use: [
{
loader: `css-loader?importLoaders=1&minimize=${IS_PROD_MIN}!postcss-loader`
},
{
loader: 'sass-loader',
options: {
outputStyle: 'expanded',
indentedSyntax: true,
includePaths: [path.join(__dirname, 'node-modules')]
}
}
],
fallback: 'style-loader'
})
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [
{
loader: `css-loader?importLoaders=1&minimize=${IS_PROD_MIN}!postcss-loader`
},
{
loader: 'sass-loader',
options: {
outputStyle: 'expanded',
includePaths: [path.join(__dirname, 'node-modules')]
}
}
],
fallback: 'style-loader'
})
},
// static assets
{test: /\.html$/, use: 'html-loader'},
{test: /\.png$/, use: 'url-loader?limit=10000'},
{test: /\.jpg$/, use: 'file-loader'},
],
},
plugins: [
new webpack.ProvidePlugin({
Promise: 'es6-promise'
}),
new webpack.optimize.AggressiveMergingPlugin(),
extractSass
],
devServer: {
contentBase: './sampleApp',
hot: true,
stats: {
warnings: false
},
},
node: {
// workaround for webpack-dev-server issue
// https://github.com/webpack/webpack-dev-server/issues/60#issuecomment-103411179
fs: 'empty',
net: 'empty'
}
};
const prod = {
devtool: 'source-map',
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new DtsBundlePlugin({
name: 'OneNotePicker',
main: `${path.resolve(__dirname)}/dist/types/src/OneNotePicker.d.ts`,
out: `${path.resolve(__dirname)}/dist/OneNotePicker.d.ts`,
removeSource: false,
outputAsModuleFolder: true,
headerText: "TypeScript Definition for OneNotePicker"
}),
new DtsBundlePlugin({
name: 'OneNotePickerApiDataProvider',
main: `${path.resolve(__dirname)}/dist/types/src/providers/OneNoteApiDataProvider.d.ts`,
out: `${path.resolve(__dirname)}/dist/OneNoteApiDataProvider.d.ts`,
removeSource: false,
outputAsModuleFolder: true,
headerText: "TypeScript Definition for OneNoteApiDataProvider"
}),
new DtsBundlePlugin({
name: 'OneNoteItemUtils',
main: `${path.resolve(__dirname)}/dist/types/src/oneNoteDataStructures/OneNoteItemUtils.d.ts`,
out: `${path.resolve(__dirname)}/dist/OneNoteItemUtils.d.ts`,
removeSource: false,
outputAsModuleFolder: true,
emitOnIncludedFileNotFound: true,
headerText: "TypeScript Definition for OneNoteItemUtils"
})
],
externals: {
'react': { root: 'React', amd: 'react', commonjs2: 'react', commonjs: 'react' },
'react-dom': { root: 'ReactDOM', amd: 'react-dom', commonjs2: 'react-dom', commonjs: 'react-dom' }
}
};
const prodMinified = {
output: {
filename: '[name].min.js'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}),
]
};
const analyze = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static'
})
]
};
let webpackConfiguration = base;
if (IS_PROD) {
webpackConfiguration = WebpackMerge(webpackConfiguration, prod);
}
if (IS_PROD_MIN) {
webpackConfiguration = WebpackMerge(webpackConfiguration, prodMinified);
}
if (IS_ANALYZE) {
webpackConfiguration = WebpackMerge(webpackConfiguration, prod);
webpackConfiguration = WebpackMerge(webpackConfiguration, analyze);
}
module.exports = webpackConfiguration;