UNPKG

2.67 kBJavaScriptView Raw
1/**
2 * @author kecso / https://github.com/kecso
3 * @author pmeijer / https://github.com/pmeijer
4 */
5
6var webpack = require('webpack'),
7 path = require('path'),
8 SRC_DIR = path.join(__dirname, 'src/client'),
9 DIST_DIR = path.join(__dirname, 'dist'),
10 isProduction = process.env.NODE_ENV ? process.env.NODE_ENV === 'production' : false;
11
12console.log('Production build mode:', isProduction);
13
14/**
15 * Conditionally loads plugins (mainly for production build)
16 * @return {Array} - Array of plugins
17 */
18function getPlugins() {
19 var plugins = [];
20
21 // Always expose NODE_ENV to webpack, you can now use `process.env.NODE_ENV`
22 // inside your code for any environment checks; UglifyJS will automatically
23 // drop any unreachable code.
24 plugins.push(new webpack.DefinePlugin({
25 "process.env": {
26 NODE_ENV: JSON.stringify(process.env.NODE_ENV)
27 }
28 }));
29
30 plugins.push(new webpack.ProvidePlugin({
31 $: "jquery",
32 jQuery: "jquery"
33 }));
34
35 // Conditionally add plugins for Production builds.
36 if (isProduction) {
37 plugins.push(new webpack.optimize.UglifyJsPlugin({minimize: true}));
38 } else { // Development plugins
39 // ...
40 }
41
42 return plugins;
43}
44module.exports = {
45 entry: {
46 main: path.join(SRC_DIR, 'main.jsx'),
47 login: path.join(SRC_DIR, 'login.jsx')
48 },
49 output: {
50 path: DIST_DIR,
51 filename: '[name].js',
52 publicPath: ''
53 },
54 module: {
55 loaders: [
56 {test: /^((?!config).)*\.(js|jsx)$/, exclude: path.join(__dirname, 'node_modules'), loader: 'babel-loader'},
57 {test: /\.css$/, loader: 'style-loader!css-loader'},
58 {test: /\.(jpg|png)$/, loader: 'file-loader'},
59
60 // **IMPORTANT** This is needed so that each bootstrap js file required by
61 // bootstrap-webpack has access to the jQuery object
62 {test: /bootstrap\/js\//, loader: 'imports-loader?jQuery=jquery'},
63
64 // Loader for react-select's less stylesheet
65 {test: /\.less$/, loader: 'style!css!less'},
66
67 // Needed for the css-loader when [bootstrap-webpack](https://github.com/bline/bootstrap-webpack)
68 // loads bootstrap's css.
69
70 // Configure font-awesome loaders
71 {test: /\.woff(2)?(\?v=\d\.\d\.\d)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff"},
72 {test: /\.(ttf|eot|svg)(\?v=\d\.\d\.\d)?$/, loader: "file-loader"}
73 ]
74 },
75 plugins: getPlugins(),
76 resolve: {
77 extensions: ['', '.js', '.jsx']
78 }
79};