-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
125 lines (118 loc) · 3.84 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
var webpack = require('webpack')
var path = require('path')
// to extract text from boundle into seperate file, like style.css, common.css etc.
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var rootConfig = require('./_config.js')
var isProduction = process.env.NODE_ENV === 'production'
var devConfig = {
entry: {
'photong': [
'webpack-dev-server/client?http://0.0.0.0:' + rootConfig.devPort || 4003,
'./src/clientReact/index.js',
],
},
output: {
path: path.resolve('public/build'),
filename: '[name].js',
publicPath: '/build/',
},
// https://github.com/MoOx/eslint-loader
// eslint options
eslint: {
fix: true,
},
module: {
preLoaders: [ {
// only process .js or .jsx file
test: /\.jsx?$/,
// ignore any file from node_modules
// exclude: /node_modules|dist|build|demo|doc/,
include: path.join(__dirname, 'src'),
// use eslint for linting(syntax checking),
// if you follow along, that will make sure our code style unified
loaders: [ 'eslint-loader' ],
} ],
loaders: [
{
test: /\.jsx?$/,
// only compile files inside this folder
include: path.join(__dirname, 'src'),
// defines which compiler(loader) should we use?
loaders: [ 'babel' ],
},
{
// for scss files
test: /\.scss$/,
exclude: /node_modules/,
loader: isProduction ?
ExtractTextPlugin.extract('style', 'css?modules&localIdentName=[local]_[hash:base64:5]!autoprefixer!sass') :
'style!css?modules&localIdentName=[path][name]___[local]---[hash:base64:5]!autoprefixer!sass',
// other options: [path][name]---[local]---[hash:base64:5]
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css'),
},
{ test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=10000' },
],
}, // end module
resolve: {
// which file extension can be require or import 'name' without specify .js .jsx
extensions: [ '', '.js', '.jsx' ],
alias: {
'PUB': path.resolve(__dirname, 'public'),
'SCSS': path.resolve(__dirname, 'scss'),
// 'react': path.resolve(__dirname, 'node_modules/react/dist/react.js'),
},
},
devServer: {
port: rootConfig.devPort || 4003,
// where is the static file located
contentBase: 'public',
watch: true,
host: 'localhost',
// if we have backend server to serve data, we can use proxy
proxy: {
'*': {
target: 'http://localhost:' + rootConfig.port || 4000,
secure: false,
// bypass: function bypass(req, res, proxyOptions) {
// if (/sockjs/.test(req.path))
// return false
// return req.path
// }
},
},
},
plugins: [
// When there are errors while compiling this plugin skips the emitting phase (and recording phase), so there are no assets emitted that include errors
new webpack.NoErrorsPlugin(),
// generate a comment banner on top of our boundle
new webpack.BannerPlugin(
`
___ ___ _____ ___ __ ___
/ _ \\/\\ /\\/___\\/__ \\/___\\/\\ \\ \\/ _ \\
/ /_)/ /_/ // // / /\\// // \\/ / /_\\/
/ ___/ __ / \\_// / / / \\_// /\\ / /_\\\\
\\/ \\/ /_/\\___/ \\/ \\___/\\_\\ \\/\\____/ photong by Eisneim(glexe.com)
****************************************************************
`
)
],
}
var prodConfig = Object.assign({}, devConfig, {
entry: {
'photong': './src/clientReact/index.js',
},
plugins: devConfig.plugins.slice(2),
})
prodConfig.plugins.push(
new webpack.DefinePlugin({
CONTRIBUTORS: JSON.stringify([ 'Eisneim' ]),
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
})
)
prodConfig.plugins.push(new ExtractTextPlugin('photong.css'))
module.exports = isProduction ? prodConfig : devConfig