-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
109 lines (107 loc) · 3.78 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
const path = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const noop = require('noop-webpack-plugin');
module.exports = (env = {}) => {
const isProduction = env.production === true;
return {
context: path.join(__dirname),
// initially, let's just have one
entry: __dirname + '/src/bundle.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'xjs-hotkeys.bundle.js',
library: 'xjs-hotkeys',
libraryTarget: 'umd',
umdNamedDefine: true
},
externals: {
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'react',
umd: 'react'
}
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
babelrc: false, // avoid any confusion
presets: [
['env', { modules: false }],
'react'
],
env: {
production: {
// additionally remove unused ES2015 classes
presets: ['minify']
}
},
plugins: ['transform-class-properties']
}
}
},
{
test: /\.s?css$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
{ loader: 'sass-loader' }
]
},
{
test: /\.(png|jpg|woff)$/,
// when building production, convert everything to inlined data URLs
// but use actual filenames in development
use: isProduction ?
{ loader: 'url-loader' } :
{
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
}
},
{
test: /\.svg$/,
use: {
loader: 'svg-url-loader'
}
}
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
isProduction ? new UglifyJSPlugin({ sourceMap: true }) : noop(),
isProduction ? new webpack.HashedModuleIdsPlugin() : noop(),
isProduction ? new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}) : noop() // allows dependencies like React to build differently in prod
],
resolve: {
// This allows imports such as: import MyClass from 'myjsfile';
extensions: ['.js', '.jsx', '.json'],
modules: [
path.resolve(__dirname, 'src'),
'node_modules'
]
},
devtool: isProduction ? 'source-map' : 'eval-source-map',
devServer: {
contentBase: './src',
hot: true
}
}
}