This repository was archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
148 lines (140 loc) · 4.03 KB
/
webpack.config.js
File metadata and controls
148 lines (140 loc) · 4.03 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var fs = require('fs');
var _ = require('lodash');
var seedling = require('seedling');
var path = require('path');
var node_modules = path.resolve(__dirname, 'node_modules');
var emissaryDir = path.resolve(__dirname, 'node_modules/emissary');
var graphiqlDir = path.resolve(__dirname, 'node_modules/graphiql');
var srcDir = path.join(__dirname, '/src');
var configDir = path.join(__dirname, '/config');
var definePlugin = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
REVISION: JSON.stringify(fs.readFileSync('/dev/stdin').toString())
}
});
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js');
var vendors = ['lodash', 'react', 'moment', 'newforms', 'react-bootstrap', 'immutable', 'q', 'react-router', 'superagent', 'fuzzy', 'react-document-title', 'react-timeago'];
var uglify = new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false
}
});
var config = {
cache:true,
context: srcDir,
eslint:{
configFile: `${node_modules}/opsee-style/.eslintrc`
},
entry: {
'index': [
'babel-polyfill',
'./js/index.jsx'
],
vendor:vendors
},
output: {
path: path.join(__dirname, "dist"),
publicPath: "/",
filename: "bundle.js",
chunkFilename: "[name]-[id].[hash].js"
},
postcss: function(webpack){
return [
require('postcss-import')({
addDependencyTo: webpack
}),
require('postcss-cssnext')({
browsers: 'last 1 version, > 10%',
features: {
customProperties: {
variables: seedling.flat
}
}
}),
require('postcss-url')()
];
},
module: {
preLoaders:[
{
test: /\.js$|\.jsx$/,
loaders: ['eslint-loader'],
exclude: [node_modules]
},
],
loaders: [
{
test: /\.js$|\.jsx$/,
loader: 'babel-loader',
query: {
plugins: ['transform-runtime'],
presets: ['es2015', 'react']
},
include: [srcDir, configDir, emissaryDir]
},
{
test: /\.css$/,
loader: 'style-loader!css-loader?module&localIdentName=[path][name]-[local]!postcss',
exclude: [graphiqlDir]
},
{
test: /\.css$/,
loader: 'style-loader!css-loader!postcss',
include: [graphiqlDir]
},
{
test: /\.json$/,
loaders: ['json']
},
{
test: /\.(png|jpg|svg)$/,
loader: 'url-loader?limit=8192',
include: [srcDir, emissaryDir]
}
]
},
noParse:vendors.map(v => `${node_modules}/${v}`),
resolve: {
extensions: ['', '.jsx', '.js', '.json', '.svg', '.png', '.jpg'],
modulesDirectories: ['node_modules', 'src/js']
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
definePlugin,
new HtmlWebpackPlugin({
hash:false,
template:'src/index.html',
favicon: 'src/img/favicon/favicon.ico'
}),
commonsPlugin
]
};
if (process.env.NODE_ENV === 'production'){
config.eslint.failOnWarning = true;
config.plugins.push(uglify);
config.plugins.push(new ExtractTextPlugin('style.css'));
config.module.loaders = config.module.loaders.map(item => {
if (_.isEqual(item.test, /\.css$/)){
if (item.loader === 'style-loader!css-loader?module&localIdentName=[path][name]-[local]!postcss'){
item.loader = ExtractTextPlugin.extract('style-loader', 'css-loader?module&localIdentName=[path][name]-[local]!postcss-loader');
} else {
item.loader = ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader');
}
}
return item;
});
} else {
config.module.loaders.splice(0, 0, {
test: /\.js$|\.jsx$/,
loaders: ['react-hot'],
include: [srcDir]
});
config.plugins.splice(1, 0, new webpack.HotModuleReplacementPlugin());
}
module.exports = config;