-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
129 lines (118 loc) · 2.89 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
const webpack = require('webpack');
const path = require('path');
// variables
const IS_PROD = process.env.NODE_ENV === "production";
const IS_ANALYZE = process.env.NODE_ENV === "analyze";
const OUT_DIR = path.join(__dirname, './dist');
// plugins
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WebpackMerge = require('webpack-merge');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const base = {
entry: {
index: './src/index.ts'
},
output: {
path: OUT_DIR,
filename: '[name].js',
library: 'OneNotePicker',
libraryTarget: 'umd',
umdNamedDefine: true
},
target: 'web',
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
devtool: 'cheap-module-eval-source-map',
module: {
rules: [
// .ts, .tsx
{
test: /\.tsx?$/,
use: IS_PROD ? 'ts-loader' : ['react-hot-loader', 'ts-loader']
},
{
test: /\.css/,
use: [
!IS_PROD ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 1 }
},
'postcss-loader'
]
},
{
test: /\.scss$/,
use: [
!IS_PROD ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 1 }
},
'postcss-loader',
'sass-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(),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new CopyWebpackPlugin([{
// The js files compiled by tsc reference images in this folder and expect it in the output path
from: path.resolve(__dirname, './src/images'),
to: './images/[name].[ext]',
toType: 'template'
}]),
],
devServer: {
contentBase: path.join(__dirname, './sampleApp'),
publicPath: '../dist/',
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 = {
mode: 'none',
plugins: [
],
externals: {
'react': { root: 'React', amd: 'react', commonjs2: 'react', commonjs: 'react' },
'react-dom': { root: 'ReactDOM', amd: 'react-dom', commonjs2: 'react-dom', commonjs: 'react-dom' }
}
};
const analyze = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static'
})
]
};
let webpackConfiguration = base;
if (IS_PROD) {
webpackConfiguration = WebpackMerge(webpackConfiguration, prod);
}
if (IS_ANALYZE) {
webpackConfiguration = WebpackMerge(webpackConfiguration, prod);
webpackConfiguration = WebpackMerge(webpackConfiguration, analyze);
}
module.exports = webpackConfiguration;