-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
123 lines (116 loc) · 3.13 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
var webpack = require('webpack')
var path = require('path')
var buildPath = path.resolve(__dirname, '')
var sourcePath = path.resolve(__dirname, 'src')
var nodeModulesPath = path.resolve(__dirname, 'node_modules')
var upupPath = path.resolve(__dirname, 'src/app/scripts/upup/')
var upupStartPath = path.resolve(__dirname, 'src/app/scripts/upup/upup.start.js')
var materialPath = path.resolve(__dirname, 'src/app/scripts/material.js')
var redirectToHTTPSPath = path.resolve(__dirname, 'src/app/scripts/redirectToHTTPS.js')
var TransferWebpackPlugin = require('transfer-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
const production = process.argv.find((element) => element === '--production') ? true : false
const jsBaseEntry = [
'babel-polyfill',
'./src/app/app.jsx',
'./src/app/scripts/material.js',
'./src/app/scripts/redirectToHTTPS.js',
]
const jsEntry = production ? jsBaseEntry.concat([
'./src/app/scripts/upup/upup.start.js',
'./src/app/scripts/upup/upup.min.js',
'./src/app/scripts/upup/upup.sw.min.js',
]) : jsBaseEntry
var config = {
entry: {
js: jsEntry,
// html: './src/www/index.html',
},
devServer:{
contentBase: 'src/www',
devtool: 'source-map',
hot: true,
inline: true,
port: 3000,
},
output: {
path: buildPath,
filename: 'scripts/boundle.min.js',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new TransferWebpackPlugin([
{from: 'www'},
], sourcePath),
new webpack.DefinePlugin({
PRODUCTION: production,
}),
new HtmlWebpackPlugin({
template: './src/www/index.html.template',
production: production,
inject: false,
}),
],
module: {
preLoaders: [
{
test: /\.(js|jsx)$/,
loader: 'eslint-loader',
include: [path.resolve(__dirname, "src/app")],
exclude: [nodeModulesPath, upupPath, materialPath, redirectToHTTPSPath],
},
],
loaders: [
{
test: /\.(js|jsx)$/,
exclude: [nodeModulesPath, upupPath, materialPath, redirectToHTTPSPath],
loaders: [
'react-hot',
'babel?' + JSON.stringify({
presets: ["react", "es2015", "stage-1"],
}),
],
},
{
test: /\.html$/,
loader: "file?name=[name].[ext]",
},
{
test: /(material|redirectToHTTPS).js$/,
loader: "file?name=scripts/[name].[ext]",
},
{
test: /upup.*.js$/,
exclude: [upupStartPath],
loader: "file?name=[name].[ext]",
},
{
test: /\upup.start.js$/,
loader: "file?name=scripts/[name].[ext]",
},
],
},
resolve: {
extensions: ['', '.ts', '.js', '.jsx'],
root: __dirname,
},
devtool: 'source-map',
eslint: {
configFile: '.eslintrc',
},
}
if (production) {
process.env.NODE_ENV = 'production'
config.plugins = [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
].concat(config.plugins)
}
module.exports = config