-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
142 lines (127 loc) · 3.83 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict'
const path = require('path')
const webpack = require('webpack')
const objectAssign = require('object-assign')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const production = process.env.NODE_ENV === 'production'
const test = process.env.NODE_ENV === 'test'
const dev = !(production || test)
let cssOutputName = null
let cssExtractPlugin = null
if (production) {
cssOutputName = '[contenthash].css'
cssExtractPlugin = new ExtractTextPlugin(cssOutputName)
}
const config = {
resolve: {
root: [
path.resolve(__dirname, 'app', 'scripts'),
path.resolve(__dirname, 'app', 'styles')
],
extensions: ['', '.js', '.jsx', '.json', 'scss'],
modulesDirectories: ['node_modules'],
alias: {
'TweenLite': path.resolve(__dirname, 'node_modules', 'gsap', 'src', 'uncompressed', 'TweenLite.js'),
'TimelineLite': path.resolve(__dirname, 'node_modules', 'gsap', 'src', 'uncompressed', 'TimelineLite.js'),
'CSSPlugin': path.resolve(__dirname, 'node_modules', 'gsap', 'src', 'uncompressed', 'plugins', 'CSSPlugin.js'),
'EasePack': path.resolve(__dirname, 'node_modules', 'gsap', 'src', 'uncompressed', 'easing', 'EasePack.js')
}
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /(node_modules)/
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file?hash=sha512&digest=hex&name=[hash].[ext]&limit=10000'
},
{
test: /\.(png|jpg|jpeg|gif|mp4|webm)$/,
loader: 'file?hash=sha512&digest=hex&name=[hash].[ext]&limit=10000'
},
{
test: /\.scss$/,
loader: production
? cssExtractPlugin.extract('style', 'css!postcss!sass')
: 'style!css!postcss!sass'
}
]
},
sassLoader: {
outputStyle: 'expanded',
includePaths: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, 'app', 'styles')
]
},
plugins: [
new webpack.ProvidePlugin({
'Promise': 'exports?global.Promise!es6-promise', // Thanks Aaron (https://gist.github.com/Couto/b29676dd1ab8714a818f#gistcomment-1584602)
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
})
]
}
if (!test) {
objectAssign(config, {
debug: dev,
devtool: dev ? 'cheap-module-eval-source-map' : undefined,
entry: [].concat(dev
? [
'eventsource-polyfill', // necessary for hot reloading with IE
'webpack-hot-middleware/client'
]
: []
).concat([path.resolve(__dirname, 'app', 'entry.js')]),
output: {
path: path.resolve(__dirname, 'public'),
publicPath: '/',
filename: '[hash].js'
},
postcss: [
require('autoprefixer')({browsers: ['last 2 version']})
].concat(production
? [require('csswring')({removeAllComments: true})]
: []
)
})
config.plugins.push(...[
new HtmlWebpackPlugin({
inject: true,
filename: 'index.html',
template: path.resolve(__dirname, 'app', 'index.template.html'),
favicon: path.resolve(__dirname, 'app', 'favicon.ico'),
minify: {
removeComments: true,
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true
}
})
])
config.plugins.push(...(production ? [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
output: {comments: false},
compress: {warnings: false}
}),
cssExtractPlugin
] : [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
]))
}
module.exports = config