|
| 1 | +/** |
| 2 | + * Common part of webpack config specific to connect app |
| 3 | + * |
| 4 | + * This config is merged to development and production configs |
| 5 | + * and is not supposed to be used directly by itself. |
| 6 | + */ |
| 7 | +'use strict' |
| 8 | + |
| 9 | +const _ = require('lodash') |
| 10 | +const path = require('path') |
| 11 | +const webpack = require('webpack') |
| 12 | +const HtmlWebpackPlugin = require('html-webpack-plugin') |
| 13 | +const constants = require('../constants') |
| 14 | + |
| 15 | +const dirname = path.resolve(__dirname, '../..') |
| 16 | + |
| 17 | +module.exports = { |
| 18 | + /* |
| 19 | + Connect app has different output folder rather than topcoder-react-utils |
| 20 | + So update it |
| 21 | + */ |
| 22 | + output: { |
| 23 | + path: path.join(dirname, '/dist'), |
| 24 | + filename: '[name].[hash].js', |
| 25 | + chunkFilename: '[name].[hash].js', |
| 26 | + publicPath: '/' |
| 27 | + }, |
| 28 | + |
| 29 | + resolve: { |
| 30 | + /* |
| 31 | + Connect app depends on `appirio-tech-react-components` which uses |
| 32 | + CoffeeScript so we have to add support for these formats |
| 33 | + */ |
| 34 | + extensions: [ |
| 35 | + '.coffee', |
| 36 | + '.litcoffee', |
| 37 | + '.cjsx' |
| 38 | + ], |
| 39 | + alias: { |
| 40 | + /* |
| 41 | + Connect app uses handlebars which has some issue with webpack |
| 42 | + We have to create an alias to concrete file in order to import it |
| 43 | + */ |
| 44 | + handlebars: 'handlebars/dist/handlebars.min.js' |
| 45 | + } |
| 46 | + }, |
| 47 | + |
| 48 | + module: { |
| 49 | + rules: [{ |
| 50 | + /* |
| 51 | + Connect app depends on `appirio-tech-react-components` which uses |
| 52 | + CoffeeScript so we have to add support for it |
| 53 | +
|
| 54 | + Note, that we use custom babel config for coffee script which disables modules |
| 55 | + */ |
| 56 | + test: /\.(coffee|litcoffee|cjsx)$/, |
| 57 | + use: [ |
| 58 | + { |
| 59 | + loader: 'babel-loader', |
| 60 | + options: { |
| 61 | + babelrc: false, |
| 62 | + forceEnv: 'development', // by default set env to 'development' |
| 63 | + presets: [path.resolve(dirname, './config/babel/webpack-coffee.js')], |
| 64 | + plugins: ['lodash'] |
| 65 | + } |
| 66 | + }, |
| 67 | + 'coffee-loader', |
| 68 | + 'cjsx-loader' |
| 69 | + ] |
| 70 | + }, { |
| 71 | + /* |
| 72 | + Load SVG files not handled by inline-react-svg babel plugin |
| 73 | + */ |
| 74 | + test: /\.svg$/, |
| 75 | + loader: 'file-loader' |
| 76 | + }], |
| 77 | + }, |
| 78 | + |
| 79 | + plugins: [ |
| 80 | + /* |
| 81 | + Connect app has a custom html template file, so we use it |
| 82 | + */ |
| 83 | + new HtmlWebpackPlugin({ |
| 84 | + template: path.join(dirname, '/src/index.html'), |
| 85 | + inject: 'body' |
| 86 | + }), |
| 87 | + |
| 88 | + /* |
| 89 | + Connect app requires a lot of env vars which are defined in constants. |
| 90 | + */ |
| 91 | + new webpack.DefinePlugin({ |
| 92 | + 'process.env': _.mapValues(constants, (value) => JSON.stringify(value)) |
| 93 | + }), |
| 94 | + |
| 95 | + /* |
| 96 | + Remove some unused files to reduce bundle size |
| 97 | + */ |
| 98 | + new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) |
| 99 | + ] |
| 100 | +} |
0 commit comments