This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
112 lines (107 loc) · 2.66 KB
/
webpack.config.babel.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
var path = require('path');
var pkg = require('./package.json');
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var
SRC = 'src',
DEV = 'dev',
DIST = 'dist',
MAIN = 'main.jsx',
HOST = 'localhost',
PORT = 9000,
ROOT_PATH = path.resolve(__dirname),
SRC_PATH = path.resolve(ROOT_PATH, SRC),
DEV_PATH = path.resolve(ROOT_PATH, DEV),
DIST_PATH = path.resolve(ROOT_PATH, DIST),
MAIN_SRC_PATH = path.resolve(SRC_PATH, MAIN),
MAIN_DEV_PATH = path.resolve(DEV_PATH, MAIN),
TARGET = process.env.npm_lifecycle_event;
if(TARGET === 'start') {
module.exports = {
resolve: {
extensions: [ "", ".js", ".jsx", ".es6" ],
alias: { src: SRC_PATH }
},
devtool: 'eval-source-map',
entry: MAIN_DEV_PATH,
output: {
path: DIST_PATH,
filename: pkg.name + '.js'
},
module: {
loaders: [
{
test: /\.(es6|jsx)$/,
loaders: ['react-hot', 'babel'],
include: [ SRC_PATH, DEV_PATH ]
},
{
test: /.*\.(gif|png|jpe?g|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]'
],
include: [ SRC_PATH, DEV_PATH ]
},
{
test: /\.scss$/,
loaders: [ 'style', 'css', 'sass' ],
include: [ SRC_PATH, DEV_PATH ]
}
]
},
devServer: {
colors:true,
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
host: HOST,
port: PORT
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlwebpackPlugin({title: pkg.description})
]
}
}
if(TARGET === 'dist') {
module.exports = {
resolve: {
extensions: [ "", ".js", ".jsx", ".es6" ],
alias: { src: SRC_PATH }
},
externals: (function(externals = {}) {
for(let key in pkg.dependencies) { externals[key] = key };
return externals;
}()),
entry: (function(entry = {}) {
entry[pkg.name] = entry[pkg.name + '.min'] = MAIN_SRC_PATH;
return entry;
}()),
output: {
path: DIST_PATH,
filename: "[name].js",
libraryTarget: 'commonjs2',
library: true
},
module: {
loaders: [
{
test: /\.(es6|jsx)$/,
loader: 'babel',
include: SRC_PATH
}
]
},
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
include: /\.min\.js$/,
mangle: {
except: ['$super', '$', 'exports', 'require']
}
})
]
}
}