Skip to content

Commit 229c7e3

Browse files
authored
Merge pull request #56 from Lemoncode/#48-review-build-config
#48 review build config
2 parents f4632bf + 8a8dfb3 commit 229c7e3

31 files changed

Lines changed: 219 additions & 131 deletions

.babelrc

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
{
2-
"presets": [
3-
"@babel/preset-react",
4-
"@babel/preset-env"
5-
]
6-
}
2+
"env": {
3+
// Compatibility Profile.
4+
// ES5 output and CommonJS module format.
5+
"es5_cjs": {
6+
"presets": [
7+
"@babel/preset-env",
8+
"@babel/preset-react"
9+
]
10+
},
11+
// Future Profile.
12+
// ES6 output with no module transformation (ES Modules syntax).
13+
"es": {
14+
"presets": [
15+
["@babel/preset-env", {
16+
"modules": false,
17+
"targets": {
18+
"node": "6.5"
19+
}
20+
}],
21+
"@babel/preset-react"
22+
]
23+
},
24+
// Bundled Profile.
25+
// ES5 output and UMD module format.
26+
"umd": {
27+
"presets": [
28+
["@babel/preset-env", {
29+
"modules": false,
30+
}],
31+
"@babel/preset-react"
32+
]
33+
},
34+
// Jest Profile.
35+
// To be used by jest tests.
36+
"test": {
37+
"presets": [
38+
"@babel/preset-env",
39+
"@babel/preset-react"
40+
]
41+
}
42+
}
43+
}

.gitignore

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
node_modules
2-
.DS_Store
3-
dist/
4-
typings/
5-
*.orig
1+
# Common aux folders
2+
.awcache/
3+
.vscode/
64
.idea/
5+
.cache/
6+
7+
# Dependencies & Build
8+
node_modules/
9+
build/
10+
11+
# Aux files
12+
*.cer
13+
*.log
14+
*/src/**/*.orig
715
*/src/**/*.js.map
16+
17+
# Win
18+
desktop.ini
19+
20+
# MacOs
21+
.DS_Store
22+
23+
# Yarn
824
yarn.lock
9-
*.log
10-
lib/
11-
es/
25+
26+
# NPM
1227
package-lock.json

config/test/polyfills.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Polyfill requestAnimationFrame required by React >=16.0.0
2+
require('raf/polyfill');

config/webpack/helpers.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const path = require('path');
2+
3+
// String helpers
4+
const capitalizeString = s => s.charAt(0).toUpperCase() + s.slice(1);
5+
const camelCaseString = dashedName => dashedName.split("-").map(
6+
(s, i) => i > 0 ? capitalizeString(s) : s
7+
).join("");
8+
9+
// Name helpers
10+
const packageName = process.env.npm_package_name;
11+
const packageNameCamelCase = camelCaseString(packageName);
12+
const version = JSON.stringify(process.env.npm_package_version).replace(/"/g, '');
13+
const getBundleFileName = min => `${packageName}-${version}${min ? ".min" : ''}.js`;
14+
15+
// Path helpers
16+
const rootPath = path.resolve(__dirname, "../..");
17+
const resolveFromRootPath = (...args) => path.join(rootPath, ...args);
18+
19+
// Export constants
20+
exports.srcPath = resolveFromRootPath("src");
21+
exports.buildPath = resolveFromRootPath("build",);
22+
exports.distPath = resolveFromRootPath("build", "dist");
23+
exports.version = version;
24+
exports.packageNameCamelCase = packageNameCamelCase;
25+
exports.getBundleFileName = getBundleFileName;

config/webpack/webpack.common.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const helpers = require('./helpers');
2+
3+
module.exports = (env, argv) => {
4+
const minimizeBundle = Boolean(argv['optimize-minimize']);
5+
6+
return {
7+
entry: ['./src/index.js'],
8+
output: {
9+
path: helpers.distPath,
10+
filename: helpers.getBundleFileName(minimizeBundle),
11+
library: helpers.packageNameCamelCase,
12+
libraryTarget: 'umd',
13+
},
14+
externals: {
15+
react: 'react',
16+
},
17+
optimization: {
18+
minimize: minimizeBundle,
19+
},
20+
module: {
21+
rules: [
22+
{
23+
test: /\.js$/,
24+
exclude: /node_modules/,
25+
loader: 'babel-loader',
26+
},
27+
],
28+
},
29+
};
30+
};

config/webpack/webpack.dev.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const merge = require('webpack-merge');
2+
const commonConfig = require('./webpack.common.js');
3+
4+
module.exports = (env, argv) => merge(commonConfig(env, argv), {
5+
mode: 'development',
6+
devtool: 'inline-source-map',
7+
});

config/webpack/webpack.prod.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const merge = require('webpack-merge');
2+
const commonConfig = require('./webpack.common.js');
3+
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
4+
const CompressionPlugin = require('compression-webpack-plugin');
5+
6+
module.exports = (env, argv) => merge(commonConfig(env, argv), {
7+
mode: 'production',
8+
devtool: 'none',
9+
plugins: [
10+
new BundleAnalyzerPlugin({
11+
analyzerMode: "static",
12+
openAnalyzer: false,
13+
reportFilename: "report/report.html",
14+
}),
15+
new CompressionPlugin(),
16+
],
17+
});

examples/00-example-basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"react": "^16.8.4",
3030
"react-dom": "^16.8.4",
3131
"react-loader-spinner": "^2.3.0",
32-
"react-promise-tracker": "file:../../"
32+
"react-promise-tracker": "file:../../build"
3333
}
3434
}

examples/00-example-basic/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
resolve: {
1111
extensions: [".js", ".jsx"],
1212
alias: {
13-
react: path.resolve('./node_modules/react')
13+
react: path.resolve('./node_modules/react'),
14+
'react-dom': path.resolve('./node_modules/react-dom')
1415
},
1516
},
1617
entry: {

0 commit comments

Comments
 (0)