-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
106 lines (96 loc) · 2.22 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
'use strict'
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const pathMap = {
local: {
dev: 'dev',
prod: 'dist',
},
server: {
dev: '../platform/frontend/',
prod: '../platform/frontend/',
},
}
const cssPath = 'styles.css'
let defaultConfig = {
location: 'local',
mode: 'dev',
}
const args = process.argv
for (const location of ['local', 'server']) {
locationPoint:
for (const mode of ['dev', 'prod']) {
if (args.indexOf(`--${location}-${mode}`) !== -1) {
defaultConfig = Object.assign(defaultConfig, {
location: location,
mode: mode,
})
break locationPoint
}
}
}
const pluginList = [
new ExtractTextPlugin(cssPath),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
}),
]
if (defaultConfig.mode === 'prod') {
pluginList.push(new webpack.optimize.UglifyJsPlugin({
compress: {},
}))
}
const deployPath = pathMap[defaultConfig.location][defaultConfig.mode]
module.exports = {
entry: {
index: './src/index.js',
},
// watch: ,
colors: true,
progress: true,
output: {
filename: '[name].js',
path: `${deployPath}`,
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
exclude: /node_modules/,
},
],
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader'),
},
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel',
query: {
optional: ['es7.decorators', 'es7.classProperties'],
},
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'file?name=static/[name].[ext]',
},
{test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'},
{test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
],
},
plugins: pluginList,
eslint: {
configFile: '.eslintrc',
plugins: [
'react',
],
},
}