UNPKG

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