-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
105 lines (102 loc) · 2.59 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
//package 變數一定要 "NODE_ENV" 為開頭
const keyName = {};
Object.keys(process.env).map((key,i)=>{
if( key.indexOf('NODE_ENV')==0){
return keyName[key] = process.env[key];
}
})
const env = keyName;
const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
template : `${__dirname}/app/index.html`,
filename : 'index.html',
inject : 'body'
});
module.exports = {
context : path.join(__dirname, "/app"),
entry : [
'./index.js',
],
output: {
library : "BrowserRouter",
path : `${__dirname}/dist/`,
filename : `./index.js`,
},
resolve:{
modules : [
path.resolve('app'),
path.resolve('app/public/images'),
path.resolve('node_modules')
]
},
module: {
loaders: [
{
test : /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader : 'babel-loader',
query : {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
}
},{
test : /\.(scss|sass)$/,
loader : ['style-loader', 'css-loader', 'sass-loader']
},{
test : /\.(jpe?g|png|gif|svg)$/,
use :[
{
loader : 'url-loader',
options: {
limt : 6000,
name : '[path][name].[ext]?[hash:8]'
}
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65
},
optipng: {
enabled: false,
},
pngquant: {
quality: '60-90',
speed: 4
},
gifsicle: {
interlaced: false,
}
}
}
]
}
],
},
devServer: {
historyApiFallback: true,
contentBase : './app',
watchContentBase : false,
inline : true,
port : 8003,
host : '0.0.0.0',
useLocalIp : false,
disableHostCheck : false,
},
plugins: [
HTMLWebpackPluginConfig,
new webpack.DefinePlugin({
'process.env': env
}),
new webpack.ProvidePlugin({
$ : 'jquery',
jQuery : 'jquery',
'window.jQuery' : 'jquery'
})
]
};