-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake-webpack-config.js
127 lines (120 loc) · 3.75 KB
/
make-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
var webpack = require('webpack');
var path = require('path');
function resolve(filePath) {
return path.resolve(__dirname, filePath);
}
module.exports = function(build, grep) {
var bowerPath = path.resolve(__dirname, 'bower_components');
var npmPath = path.resolve(__dirname, 'node_modules');
var autoprefixerConfig = {
browsers: ['Firefox > 27', 'Chrome > 20', 'Explorer > 9', 'Safari > 6', 'Opera > 11.5', 'iOS > 6.1'],
};
var sassConfig = {
outputStyle: 'compressed',
includePaths: [bowerPath, npmPath],
};
var jsxExcludes = [/node_modules/, /bower_components/];
var config = {
resolve: {
extensions: ['', '.js', '.jsx'],
root: [npmPath, bowerPath, resolve('src')],
},
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
),
],
module: {
loaders: [
{
test: /\.scss$/,
loader: 'style!css!autoprefixer?' + JSON.stringify(autoprefixerConfig) + '!sass?' + JSON.stringify(sassConfig),
},
{
test: /\.css$/,
loader: 'style!css!autoprefixer?' + JSON.stringify(autoprefixerConfig),
},
{ test: /\.png$/, loader: 'file' },
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&minetype=application/font-woff' },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&minetype=application/font-woff' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&minetype=application/octet-stream' },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&minetype=image/svg+xml' },
{ test: /\.json$/, loader: 'json' },
],
},
};
switch (build) {
case 'test':
config.devtool = 'inline-source-map';
config.cache = true;
config.output = {
path: resolve('./dist/'),
filename: 'test.js',
publicPath: '/dist/',
};
config.module.loaders.push({
test: /\.jsx?$/,
loaders: ['babel-loader?stage=0'],
exclude: jsxExcludes,
});
config.plugins.push(
new webpack.DefinePlugin({
// This allows to dynamically define what test files we want to run
// See karma.conf.js
GREP: grep || '/\\.spec\\.jsx?$/',
}),
new webpack.ProvidePlugin({
expect: 'expect',
})
);
break;
case 'dev':
// This is not as dirty as it looks. It just generates source maps without being crazy slow.
// Source map lines will be slightly offset, use config.devtool = 'source-map'; to generate cleaner source maps.
config.devtool = 'eval';
config.cache = true;
config.entry = [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./example/index.jsx',
];
config.output = {
path: resolve('./dist/'),
filename: 'test.js',
publicPath: '/dist/',
};
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
);
config.module.loaders.push({
test: /\.jsx?$/,
loaders: ['react-hot-loader', 'babel-loader?stage=0', 'eslint-loader'],
exclude: jsxExcludes,
});
break;
case 'dist':
config.plugins.push(
new webpack.optimize.UglifyJsPlugin()
);
case 'optimize':
config.entry = './src/index';
config.output = {
path: resolve('./dist/'),
filename: 'index.js',
publicPath: '/dist/',
libraryTarget: 'amd',
};
config.plugins.push(
new webpack.optimize.DedupePlugin()
);
config.module.loaders.push({
test: /\.jsx?$/,
loaders: ['babel-loader?stage=0'],
exclude: jsxExcludes,
});
break;
}
return config;
};