Skip to content

Commit 81c3cab

Browse files
committed
webpack config without hot reload changes in project
1 parent 0dcf0a1 commit 81c3cab

File tree

9 files changed

+5464
-1685
lines changed

9 files changed

+5464
-1685
lines changed

.babelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// this babel config is for tests only
2+
// babel config for client side is places inside webpack config
13
{
2-
"presets": ["es2015", "react", "stage-2"]
4+
"presets": ["env", "react", "stage-2"]
35
}

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore dist directory to speed up linting after we build project
2+
dist/*

config/constants.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
const configEnvConstants = function(ENV) {
2+
const constants = {}
3+
4+
if (ENV === 'DEV') {
5+
Object.assign(constants, {
6+
API_URL : 'https://api.topcoder-dev.com/v3',
7+
API_URL_V2 : 'https://api.topcoder-dev.com/v2',
8+
WORK_API_URL : 'https://api-work.topcoder-dev.com/v3',
9+
INTERNAL_API_URL : 'https://internal-api.topcoder-dev.com/v3',
10+
ASSET_PREFIX : 'https://s3.amazonaws.com/app.topcoder-dev.com/',
11+
AUTH_API_URL : 'https://api.topcoder-dev.com/v3',
12+
auth0Callback : 'https://api.topcoder-dev.com/pub/callback.html',
13+
auth0Domain : 'topcoder-dev.auth0.com',
14+
clientId : process.env.AUTH0_CLIENT_ID_DEV,
15+
AUTH0_DOMAIN : 'topcoder-dev.auth0.com',
16+
AUTH0_CLIENT_ID : process.env.AUTH0_CLIENT_ID_DEV,
17+
domain : 'topcoder-dev.com',
18+
DOMAIN : 'topcoder-dev.com',
19+
ENV : 'DEV',
20+
21+
NEW_RELIC_APPLICATION_ID: process.env.TRAVIS_BRANCH ? '8957921' : '',
22+
23+
ARENA_URL : '//arena.topcoder-dev.com',
24+
BLOG_LOCATION : 'https://www.topcoder-dev.com/feed/',
25+
COMMUNITY_URL : '//community.topcoder-dev.com',
26+
FORUMS_APP_URL : '//apps.topcoder-dev.com/forums',
27+
HELP_APP_URL : 'help.topcoder-dev.com',
28+
MAIN_URL : 'https://www.topcoder-dev.com',
29+
PHOTO_LINK_LOCATION: 'https://community.topcoder-dev.com',
30+
SWIFT_PROGRAM_URL : 'apple.topcoder-dev.com',
31+
TCO16_URL : 'http://tco16.topcoder-dev.com',
32+
TCO17_URL : 'http://tco17.topcoder-dev.com',
33+
TCO_HOME_URL : 'https://www.topcoder-dev.com/tco',
34+
35+
ACCOUNTS_APP_URL : 'https://accounts.topcoder-dev.com/#!/member',
36+
ACCOUNTS_APP_CONNECTOR_URL : 'https://accounts.topcoder-dev.com/connector.html',
37+
38+
FILE_PICKER_API_KEY: process.env.FILE_PICKER_API_KEY_DEV,
39+
FILE_PICKER_SUBMISSION_CONTAINER_NAME: 'submission-staging-dev',
40+
41+
SALESFORCE_PROJECT_LEAD_LINK: 'https://c.cs18.visual.force.com/apex/ConnectLead?connectProjectId=',
42+
43+
CONNECT_SEGMENT_KEY: 'QBtLgV8vCiuRX1lDikbMjcoe9aCHkF6n',
44+
PREDIX_PROGRAM_ID : 3448,
45+
IBM_COGNITIVE_PROGRAM_ID : 3449,
46+
HEAP_ANALYTICS_APP_ID : '4153837120'
47+
})
48+
}
49+
50+
if (ENV === 'QA') {
51+
Object.assign(constants, {
52+
API_URL : 'https://api.topcoder-qa.com/v3',
53+
API_URL_V2 : 'https://api.topcoder-qa.com/v2',
54+
WORK_API_URL : 'https://api-work.topcoder-qa.com/v3',
55+
INTERNAL_API_URL : 'https://internal-api.topcoder-qa.com/v3',
56+
ASSET_PREFIX : 'https://s3.amazonaws.com/app.topcoder-qa.com/',
57+
AUTH_API_URL : 'https://api.topcoder-qa.com/v3',
58+
auth0Callback : 'https://api.topcoder-qa.com/pub/callback.html',
59+
auth0Domain : 'topcoder-qa.auth0.com',
60+
clientId : process.env.AUTH0_CLIENT_ID_QA,
61+
AUTH0_DOMAIN : 'topcoder-qa.auth0.com',
62+
AUTH0_CLIENT_ID : process.env.AUTH0_CLIENT_ID_QA,
63+
domain : 'topcoder-qa.com',
64+
DOMAIN : 'topcoder-qa.com',
65+
ENV : 'QA',
66+
67+
NEW_RELIC_APPLICATION_ID: process.env.TRAVIS_BRANCH ? '11199233' : '',
68+
69+
ARENA_URL : '//arena.topcoder-qa.com',
70+
BLOG_LOCATION : 'https://www.topcoder-qa.com/feed/',
71+
COMMUNITY_URL : '//community.topcoder-qa.com',
72+
FORUMS_APP_URL : '//apps.topcoder-qa.com/forums',
73+
HELP_APP_URL : 'help.topcoder-qa.com',
74+
MAIN_URL : 'https://www.topcoder-qa.com',
75+
PHOTO_LINK_LOCATION: 'https://community.topcoder-qa.com',
76+
SWIFT_PROGRAM_URL : 'apple.topcoder-qa.com',
77+
TCO16_URL : 'http://tco16.topcoder-qa.com',
78+
TCO17_URL : 'http://tco17.topcoder-qa.com',
79+
TCO_HOME_URL : 'https://www.topcoder-dev.com/tco',
80+
81+
ACCOUNTS_APP_URL : 'https://accounts.topcoder-qa.com/#!/member',
82+
ACCOUNTS_APP_CONNECTOR_URL : 'https://accounts.topcoder-qa.com/connector.html',
83+
84+
FILE_PICKER_API_KEY: process.env.FILE_PICKER_API_KEY_QA,
85+
FILE_PICKER_SUBMISSION_CONTAINER_NAME: 'submission-staging-qa',
86+
87+
SALESFORCE_PROJECT_LEAD_LINK: 'https://c.cs18.visual.force.com/apex/ConnectLead?connectProjectId=',
88+
CONNECT_SEGMENT_KEY: '',
89+
PREDIX_PROGRAM_ID : 3448,
90+
IBM_COGNITIVE_PROGRAM_ID : 3449,
91+
HEAP_ANALYTICS_APP_ID : '4153837120'
92+
})
93+
}
94+
95+
if (ENV === 'PROD') {
96+
Object.assign(constants, {
97+
API_URL : 'https://api.topcoder.com/v3',
98+
API_URL_V2 : 'https://api.topcoder.com/v2',
99+
WORK_API_URL : 'https://api-work.topcoder.com/v3',
100+
INTERNAL_API_URL : 'https://internal-api.topcoder.com/v3',
101+
ASSET_PREFIX : 'https://s3.amazonaws.com/app.topcoder.com/',
102+
AUTH_API_URL : 'https://api.topcoder.com/v3',
103+
auth0Callback : 'https://api.topcoder.com/pub/callback.html',
104+
auth0Domain : 'topcoder.auth0.com',
105+
clientId : process.env.AUTH0_CLIENT_ID_PROD,
106+
AUTH0_DOMAIN : 'topcoder.auth0.com',
107+
AUTH0_CLIENT_ID : process.env.AUTH0_CLIENT_ID_PROD,
108+
domain : 'topcoder.com',
109+
DOMAIN : 'topcoder.com',
110+
ENV : 'PROD',
111+
NODE_ENV : 'production',
112+
113+
NEW_RELIC_APPLICATION_ID: process.env.TRAVIS_BRANCH ? '11352758' : '',
114+
115+
ARENA_URL : '//arena.topcoder.com',
116+
BLOG_LOCATION : 'https://www.topcoder.com/feed/',
117+
COMMUNITY_URL : '//community.topcoder.com',
118+
FORUMS_APP_URL : '//apps.topcoder.com/forums',
119+
HELP_APP_URL : 'help.topcoder.com',
120+
MAIN_URL : 'https://www.topcoder.com',
121+
PHOTO_LINK_LOCATION: 'https://community.topcoder.com',
122+
SWIFT_PROGRAM_URL : 'apple.topcoder.com',
123+
TCO16_URL : 'http://tco16.topcoder.com',
124+
TCO17_URL : 'http://tco17.topcoder.com',
125+
TCO_HOME_URL : 'https://www.topcoder.com/tco',
126+
127+
ACCOUNTS_APP_URL : 'https://accounts.topcoder.com/#!/member',
128+
ACCOUNTS_APP_CONNECTOR_URL : 'https://accounts.topcoder.com/connector.html',
129+
130+
FILE_PICKER_API_KEY: process.env.FILE_PICKER_API_KEY_PROD,
131+
FILE_PICKER_SUBMISSION_CONTAINER_NAME: 'submission-staging-prod',
132+
133+
SALESFORCE_PROJECT_LEAD_LINK: 'https://topcoder.my.salesforce.com/apex/ConnectLead?connectProjectId=',
134+
CONNECT_SEGMENT_KEY: 'ajP6cQ5SN2EMUWoWTOLROVnAHsOlsDCn',
135+
PREDIX_PROGRAM_ID : 3448,
136+
IBM_COGNITIVE_PROGRAM_ID : 3449,
137+
HEAP_ANALYTICS_APP_ID : '638908330'
138+
})
139+
}
140+
141+
return constants
142+
}
143+
144+
module.exports = configEnvConstants

config/webpack/default.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
'use strict'
2+
3+
const _ = require('lodash')
4+
const path = require('path')
5+
const webpack = require('webpack')
6+
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
7+
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin')
8+
const HtmlWebpackPlugin = require('html-webpack-plugin')
9+
10+
const constants = require('../constants.js')
11+
12+
const branch = process.env.CIRCLE_BRANCH
13+
let env = 'DEV' // Default to DEV
14+
if (branch === 'master') env = 'PROD'
15+
if (branch === 'dev') env = 'DEV'
16+
if (branch === 'qa') env = 'QA'
17+
const envConstants = constants(env)
18+
19+
const dirname = path.resolve(__dirname, '../..')
20+
21+
module.exports = {
22+
context: dirname,
23+
24+
entry: [
25+
'./src/styles/main.scss',
26+
'./src/index'
27+
],
28+
29+
output: {
30+
path : path.join(dirname, '/dist'),
31+
filename : '[name].[hash].js',
32+
chunkFilename : '[name].[hash].js'
33+
},
34+
35+
module: {
36+
rules: [{
37+
test: /\.(js|jsx)$/,
38+
loader: 'babel-loader',
39+
exclude: /node_modules\/(?!appirio-tech.*|topcoder|tc-)/,
40+
options: {
41+
babelrc: false,
42+
presets: [ 'env', 'react', 'stage-2' ],
43+
plugins: [ 'lodash' ]
44+
}
45+
}, {
46+
test: /\.(coffee|litcoffee|cjsx)$/,
47+
use: [
48+
{
49+
loader: 'babel-loader',
50+
options: {
51+
babelrc: false,
52+
presets: [ 'env', 'react', 'stage-2' ],
53+
plugins: [ 'lodash' ]
54+
}
55+
},
56+
'coffee-loader',
57+
'cjsx-loader'
58+
]
59+
}, {
60+
test: /\.json$/,
61+
loader: 'json-loader'
62+
}, {
63+
/* We have to support css loading for third-party plugins,
64+
* we are not supposed to use css files inside the project. */
65+
test: /\.css$/,
66+
use: ExtractCssChunks.extract({
67+
fallback: 'style-loader',
68+
use: ['css-loader']
69+
})
70+
}, {
71+
// ASSET LOADER
72+
// Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output
73+
// Rename the file using the asset hash
74+
// Pass along the updated reference to your code
75+
// You can add here any file extension you want to get copied to your output
76+
test: /\.(png|jpg|jpeg|gif)$/,
77+
loader: 'file-loader'
78+
}, {
79+
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
80+
loader: 'file-loader'
81+
}, {
82+
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
83+
loader: 'file-loader'
84+
}]
85+
86+
},
87+
88+
resolve: {
89+
extensions: [
90+
'.js',
91+
'.jsx',
92+
'.json',
93+
'.coffee',
94+
'.scss',
95+
'.svg',
96+
'.png',
97+
'.gif',
98+
'.jpg',
99+
'.cjsx'
100+
]
101+
},
102+
103+
plugins: [
104+
new webpack.DefinePlugin({
105+
'process.env': _.mapValues(envConstants, (value) => JSON.stringify(value))
106+
}),
107+
new FaviconsWebpackPlugin({
108+
logo: './src/favicon.png',
109+
// disable cache, otherwise when there is a dist folder with icons
110+
// icons don't wanna be generated in memory using webpack-dev-server
111+
persistentCache: false
112+
}),
113+
new HtmlWebpackPlugin({
114+
template: path.join(dirname, '/src/index.html'),
115+
inject: 'body'
116+
}),
117+
// Only emit files when there are no errors
118+
new webpack.NoEmitOnErrorsPlugin(),
119+
new ExtractCssChunks({
120+
filename: '[name].css',
121+
justExtract: true
122+
})
123+
]
124+
}

config/webpack/development.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const path = require('path')
2+
const webpack = require('webpack')
3+
const webpackMerge = require('webpack-merge')
4+
5+
const defaultConfig = require('./default')
6+
7+
const dirname = path.resolve(__dirname, '../..')
8+
9+
module.exports = webpackMerge(defaultConfig, {
10+
entry: [
11+
'react-hot-loader/patch'
12+
],
13+
14+
devtool: 'eval',
15+
16+
module: {
17+
rules: [{
18+
test: /\.(js|jsx)$/,
19+
loader: 'babel-loader',
20+
exclude: /node_modules\/(?!appirio-tech.*|topcoder|tc-)/,
21+
options: {
22+
babelrc: false,
23+
presets: [ ['env', { modules: false }], 'react', 'stage-2' ],
24+
plugins: [
25+
'lodash',
26+
// add react hot reloader
27+
'react-hot-loader/babel'
28+
]
29+
}
30+
}, {
31+
test: /\.scss$/,
32+
use: [
33+
'style-loader',
34+
{
35+
loader: 'css-loader',
36+
options: {
37+
sourceMap: true
38+
}
39+
},
40+
'resolve-url-loader',
41+
{
42+
loader: 'sass-loader',
43+
options: {
44+
sourceMap: true,
45+
includePaths: [
46+
path.join(dirname, '/node_modules/bourbon/app/assets/stylesheets'),
47+
path.join(dirname, '/node_modules/tc-ui/src/styles')
48+
]
49+
}
50+
}
51+
]
52+
}]
53+
},
54+
55+
plugins: [
56+
// don't add HotModuleReplacementPlugin, because run webpack-dev-server with --hot param
57+
// otherwise this plugin will be added twice and cause bugs
58+
// new webpack.HotModuleReplacementPlugin(),
59+
60+
new webpack.NamedModulesPlugin()
61+
]
62+
})

config/webpack/production.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const path = require('path')
2+
const webpack = require('webpack')
3+
const webpackMerge = require('webpack-merge')
4+
const CompressionPlugin = require('compression-webpack-plugin')
5+
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin')
6+
7+
const defaultConfig = require('./default')
8+
9+
const dirname = path.resolve(__dirname, '../..')
10+
11+
module.exports = webpackMerge(defaultConfig, {
12+
devtool: 'source-map',
13+
14+
module: {
15+
rules: [{
16+
test: /\.scss$/,
17+
use: ExtractCssChunks.extract({
18+
fallback: 'style-loader',
19+
use: [{
20+
loader: 'css-loader',
21+
options: {
22+
sourceMap: true
23+
}
24+
},
25+
'resolve-url-loader',
26+
{
27+
loader: 'sass-loader',
28+
options: {
29+
sourceMap: true,
30+
includePaths: [
31+
path.join(dirname, '/node_modules/bourbon/app/assets/stylesheets'),
32+
path.join(dirname, '/node_modules/tc-ui/src/styles')
33+
]
34+
}
35+
}]
36+
})
37+
}]
38+
},
39+
40+
plugins: [
41+
// Do not include any .mock.js files if this is a build
42+
new webpack.IgnorePlugin(/\.mock\.js/),
43+
new webpack.optimize.UglifyJsPlugin({
44+
mangle: true
45+
}),
46+
new CompressionPlugin({
47+
asset: '[file]',
48+
algorithm: 'gzip',
49+
regExp: /\.js$|\.css$/,
50+
threshold: 10240,
51+
minRatio: 0.8
52+
})
53+
]
54+
})

0 commit comments

Comments
 (0)