|
| 1 | +/* eslint-disable */ |
| 2 | +/** |
| 3 | + * https://github.com/jonathanewerner/pac |
| 4 | + * An Electron packager manager desktop app |
| 5 | + */ |
| 6 | + |
| 7 | +const path = require('path'); |
| 8 | +const autoprefixer = require('autoprefixer'); |
| 9 | +const webpack = require('webpack'); |
| 10 | +const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 11 | + |
| 12 | +const lessModuleLoader = (prod) => { |
| 13 | + const cssModulesOptions = prod ? '' : '&localIdentName=[name]__[local]___[hash:base64:5]'; |
| 14 | + const _loaders = `css?modules${cssModulesOptions}!postcss!less`; |
| 15 | + return { |
| 16 | + test: /\.less.module$/, |
| 17 | + loader: !prod ? `style!${_loaders}` : |
| 18 | + ExtractTextPlugin.extract('style', _loaders, {publicPath: ''}), |
| 19 | + }; |
| 20 | +}; |
| 21 | + |
| 22 | +export const makeConfig = ({production}) => ({ |
| 23 | + resolve: { |
| 24 | + extensions: ['', '.js', '.jsx'], |
| 25 | + modulesDirectories: ['node_modules', 'src'], |
| 26 | + }, |
| 27 | + entry: { |
| 28 | + app: production |
| 29 | + ? ['./configs.js'] |
| 30 | + : ['webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr&reload=true', './configs.js'], |
| 31 | + }, |
| 32 | + output: { |
| 33 | + path: path.join(__dirname, 'public'), |
| 34 | + publicPath: '/public/', |
| 35 | + filename: 'bundle.js', |
| 36 | + }, |
| 37 | + module: { |
| 38 | + loaders: [ |
| 39 | + { |
| 40 | + test: /\.jsx?$/, |
| 41 | + include: /src/, |
| 42 | + loader: 'babel', |
| 43 | + }, |
| 44 | + { |
| 45 | + test: /\.less$/, |
| 46 | + loader: 'style-loader!css-loader!autoprefixer-loader?{browsers:["last 2 version"]}!less-loader', |
| 47 | + }, |
| 48 | + { |
| 49 | + test: /\.(?:eot|ttf|woff2?)$/, |
| 50 | + loader: 'file-loader?name=[path][name]-[hash:6].[ext]&context=assets', |
| 51 | + }, |
| 52 | + ].concat([ |
| 53 | + lessModuleLoader(false), |
| 54 | + ]), |
| 55 | + }, |
| 56 | + postcss: function() { |
| 57 | + return [autoprefixer({browsers: ['last 2 versions']})]; |
| 58 | + }, |
| 59 | + plugins: [ |
| 60 | + new webpack.DefinePlugin({ |
| 61 | + 'process.env': {NODE_ENV: JSON.stringify(process.env.NODE_ENV)}, |
| 62 | + }), |
| 63 | + |
| 64 | + // Moment.js imports the locales dynamically which is why webpack will include all 60 locales (>300kb) |
| 65 | + // if we don't override this behaviour. |
| 66 | + // Here we "whitelist" the paths that will be imported when moment/locales/* is imported |
| 67 | + // We tell it that we are interested in de, en-gb, da & nl. Afrikaans etc. will stay out. :) |
| 68 | + // This results in a bundle size reduction of 300kb / 150KB minified |
| 69 | + new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /(de|en-gb|da|nl)$/), |
| 70 | + ].concat(production ? [ |
| 71 | + new webpack.optimize.UglifyJsPlugin({ |
| 72 | + // compress: {drop_console: true}, |
| 73 | + sourceMap: false, // This means dropping build time from ~45 sec to ~32 sec |
| 74 | + })] : []), |
| 75 | + devtool: 'hidden-source-map', |
| 76 | +}); |
| 77 | + |
| 78 | +export default makeConfig({production: true}); |
0 commit comments