Skip to content

Commit d6d9ff6

Browse files
committed
- upgraded to topcoder-react-utils@0.0.39
- fixed production builds - fixed to reuse `entry` from topcoder-react-utils
1 parent 47a89d7 commit d6d9ff6

File tree

7 files changed

+1073
-60
lines changed

7 files changed

+1073
-60
lines changed

config/babel/webpack-coffee.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Babel config for CoffeeScript only.
3+
*
4+
* We disable modules for `env` preset of `babel` for CoffeeScript to avoid error
5+
* 'Uncaught ReferenceError exports is not defined'
6+
*/
7+
const topCoderBabelConfig = require('topcoder-react-utils/config/babel/webpack')
8+
9+
const envPresetIndex = topCoderBabelConfig.presets.find((preset) => preset === 'env')
10+
topCoderBabelConfig.presets.splice(envPresetIndex, 1, ['env', { modules: false }])
11+
12+
console.log('babel', JSON.stringify(topCoderBabelConfig, null, 4))
13+
14+
module.exports = topCoderBabelConfig

config/webpack/common.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ module.exports = {
5050
/*
5151
Connect app depends on `appirio-tech-react-components` which uses
5252
CoffeeScript so we have to add support for it
53+
54+
Note, that we use custom babel config for coffee script which disables modules
5355
*/
5456
test: /\.(coffee|litcoffee|cjsx)$/,
5557
use: [
5658
{
5759
loader: 'babel-loader',
5860
options: {
5961
babelrc: false,
60-
presets: ['env', 'react', 'stage-2'],
62+
forceEnv: 'development', // by default set env to 'development'
63+
presets: [path.resolve(dirname, './config/babel/webpack-coffee.js')],
6164
plugins: ['lodash']
6265
}
6366
},
@@ -66,7 +69,7 @@ module.exports = {
6669
]
6770
}, {
6871
/*
69-
Without this rule there are lots of SVG issues
72+
Load SVG files not handled by inline-react-svg babel plugin
7073
*/
7174
test: /\.svg$/,
7275
loader: 'file-loader'

config/webpack/development.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,30 @@ const configFactory = require('topcoder-react-utils/config/webpack/app-developme
1414
const developmentTopCoderConfig = configFactory({
1515
context: dirname,
1616

17-
entry: [
18-
'react-hot-loader/patch',
19-
'./src/styles/main.scss',
20-
'./src/index'
21-
]
17+
entry: './src/index'
2218
})
2319

20+
// merge standard development TopCoder config with common config specific to connect app
21+
const combinedConfig = webpackMerge.smart(
22+
developmentTopCoderConfig,
23+
commonProjectConfig
24+
)
25+
2426
// apply common modifications specific to connect app which cannot by applied by webpack merge
25-
applyCommonModifications(developmentTopCoderConfig)
27+
applyCommonModifications(combinedConfig)
2628

2729
/*
2830
Remove HotModuleReplacementPlugin, because we run webpack-dev-server with --hot param
2931
Otherwise this plugin will be added twice and cause bugs
3032
*/
31-
const hotReloadPluginIndex = developmentTopCoderConfig.plugins.findIndex(plugin => plugin.constructor.name === 'HotModuleReplacementPlugin')
32-
developmentTopCoderConfig.plugins.splice(hotReloadPluginIndex, 1)
33+
const hotReloadPluginIndex = combinedConfig.plugins.findIndex(plugin => plugin.constructor.name === 'HotModuleReplacementPlugin')
34+
combinedConfig.plugins.splice(hotReloadPluginIndex, 1)
3335

34-
// merge standard development TopCoder config with common config specific to connect app
35-
const combinedConfig = webpackMerge.smart(
36-
developmentTopCoderConfig,
37-
commonProjectConfig
38-
)
36+
/*
37+
Remove 'webpack-hot-middleware/client?reload=true' as we use webpack-dev-server, not middleware
38+
*/
39+
combinedConfig.entry.main = combinedConfig.entry.main.filter((entry) => (
40+
entry !== 'webpack-hot-middleware/client?reload=true'
41+
))
3942

4043
module.exports = combinedConfig

config/webpack/production.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,29 @@ const configFactory = require('topcoder-react-utils/config/webpack/app-productio
1515
const productionTopCoderConfig = configFactory({
1616
context: dirname,
1717

18-
entry: [
19-
'./src/styles/main.scss',
20-
'./src/index'
21-
]
18+
entry: './src/index'
2219
})
2320

21+
// merge standard production TopCoder config with common config specific to connect app
22+
const combinedConfig = webpackMerge.smart(
23+
productionTopCoderConfig,
24+
commonProjectConfig
25+
)
26+
2427
// apply common modifications specific to connect app which cannot by applied by webpack merge
25-
applyCommonModifications(productionTopCoderConfig)
28+
applyCommonModifications(combinedConfig)
29+
30+
/*
31+
Set babel environment to `production` for CoffeeScript babel config
32+
*/
33+
const coffeeRule = combinedConfig.module.rules.find(rule => /coffee/.test(rule.test.toString()))
34+
const coffeeBabelUse = coffeeRule.use.find((use) => use.loader === 'babel-loader')
35+
coffeeBabelUse.options.forceEnv = 'production'
2636

2737
/*
2838
Add compression plugin which gzip files output files
2939
*/
30-
productionTopCoderConfig.plugins.push(
40+
combinedConfig.plugins.push(
3141
new CompressionPlugin({
3242
asset: '[file]',
3343
algorithm: 'gzip',
@@ -37,10 +47,4 @@ productionTopCoderConfig.plugins.push(
3747
})
3848
)
3949

40-
// merge standard production TopCoder config with common config specific to connect app
41-
const combinedConfig = webpackMerge.smart(
42-
productionTopCoderConfig,
43-
commonProjectConfig
44-
)
45-
4650
module.exports = combinedConfig

0 commit comments

Comments
 (0)