Skip to content

Commit 15216fb

Browse files
ealmansiryanxcharles
authored andcommitted
Added production build for browsers on all isomorphic libraries. (#1399)
1 parent 3957f99 commit 15216fb

File tree

5 files changed

+125
-36
lines changed

5 files changed

+125
-36
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
lib/
2-
*.log
1+
dist/
2+
*.log

package.json

+23-13
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,51 @@
22
"name": "mb-logger",
33
"version": "0.1.0",
44
"description": "MoneyButton isomorphic logger.",
5-
"main": "lib/index.js",
5+
"main": "dist/mb-logger.cjs.js",
6+
"module": "dist/mb-logger.esm.js",
7+
"browser": "dist/mb-logger.umd.js",
8+
"library": "logger",
9+
"files": ["dist/**"],
610
"scripts": {
711
"lint": "standard --parser=babel-eslint",
812
"pretest": "yarn lint",
913
"test": "yarn test:mocha",
1014
"test:mocha": "NODE_ENV=test mocha -R progress",
11-
"build": "babel src -d lib",
12-
"build:watch": "babel -w src -d lib",
13-
"dev": "NODE_ENV=dev yarn build:watch"
15+
"build":
16+
"concurrently --names 'browser,node' 'yarn build:browser' 'yarn build:node'",
17+
"build:watch":
18+
"concurrently --names 'browser,node' 'yarn build:browser -w' 'yarn build:node -w'",
19+
"build:browser": "webpack",
20+
"build:node": "rollup -c",
21+
"dev": "yarn build:watch"
1422
},
1523
"repository": "https://github.com/yoursnetwork/yours",
1624
"author": "Yours Inc.",
1725
"license": "UNLICENSED",
1826
"private": true,
1927
"dependencies": {
2028
"@babel/runtime": "7.0.0-beta.47",
21-
"winston": "3.0.0-rc5"
29+
"loglevel": "1.6.1"
2230
},
2331
"devDependencies": {
24-
"babel-eslint": "8.2.5",
2532
"@babel/cli": "7.0.0-beta.47",
2633
"@babel/core": "7.0.0-beta.47",
34+
"@babel/plugin-external-helpers": "7.0.0-beta.55",
2735
"@babel/plugin-transform-runtime": "7.0.0-beta.47",
2836
"@babel/preset-env": "7.0.0-beta.47",
2937
"@babel/register": "7.0.0-beta.47",
38+
"babel-eslint": "8.2.5",
39+
"babel-loader": "8.0.0-beta.4",
40+
"concurrently": "3.6.1",
3041
"mocha": "5.2.0",
42+
"rollup": "0.63.4",
43+
"rollup-plugin-babel": "4.0.0-beta.7",
3144
"should": "13.2.1",
32-
"standard": "11.0.1"
45+
"standard": "11.0.1",
46+
"webpack": "4.16.3",
47+
"webpack-cli": "3.1.0"
3348
},
3449
"standard": {
35-
"globals": [
36-
"afterEach",
37-
"beforeEach",
38-
"describe",
39-
"it"
40-
]
50+
"globals": ["afterEach", "beforeEach", "describe", "it"]
4151
}
4252
}

rollup.config.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import babel from 'rollup-plugin-babel'
2+
import path from 'path'
3+
import pkg from './package.json'
4+
5+
function isExternal (candidate) {
6+
return Object.keys(pkg.dependencies).some(dependency => {
7+
return candidate.startsWith(dependency)
8+
})
9+
}
10+
11+
export default [
12+
{
13+
input: path.resolve(__dirname, 'src', 'index.js'),
14+
external: isExternal,
15+
output: [
16+
{
17+
file: pkg.main,
18+
format: 'cjs',
19+
sourcemap: true
20+
},
21+
{
22+
file: pkg.module,
23+
format: 'es',
24+
sourcemap: true
25+
}
26+
],
27+
plugins: [
28+
babel({
29+
runtimeHelpers: true,
30+
exclude: ['node_modules/**'],
31+
presets: [
32+
[
33+
'@babel/preset-env',
34+
{
35+
modules: false,
36+
targets: {
37+
node: 'current'
38+
}
39+
}
40+
]
41+
],
42+
plugins: [
43+
'@babel/plugin-external-helpers',
44+
'@babel/plugin-transform-runtime'
45+
]
46+
})
47+
]
48+
}
49+
]

src/index.js

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
import winston from 'winston'
1+
import * as log from 'loglevel'
22

3-
export default winston.createLogger({
4-
transports: [
5-
new winston.transports.Console({
6-
format: winston.format.simple(),
7-
level: 'debug',
8-
handleExceptions: true,
9-
json: false,
10-
colorize: true
11-
}),
12-
new winston.transports.File({
13-
level: 'error',
14-
filename: 'mb-api-error.log',
15-
handleExceptions: true,
16-
json: true,
17-
maxsize: 5 * 1024 * 1024, // 5MB
18-
maxFiles: 5,
19-
colorize: false
20-
})
21-
]
22-
})
3+
export default log

webpack.config.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const path = require('path')
2+
const pkg = require('./package')
3+
4+
const shared = {
5+
entry: path.resolve(__dirname, 'src', 'index.js'),
6+
module: {
7+
rules: [
8+
{
9+
test: /\.js$/,
10+
exclude: /(node_modules)/,
11+
use: {
12+
loader: 'babel-loader',
13+
options: {
14+
presets: [
15+
[
16+
'@babel/preset-env',
17+
{
18+
targets: {
19+
browsers: ['> 2%']
20+
}
21+
}
22+
]
23+
]
24+
}
25+
}
26+
}
27+
]
28+
},
29+
output: {
30+
path: __dirname,
31+
filename: pkg.browser,
32+
library: pkg.library,
33+
libraryTarget: 'umd'
34+
}
35+
}
36+
37+
const dev = {
38+
...shared,
39+
mode: 'development',
40+
devtool: 'eval-source-map'
41+
}
42+
43+
const prod = {
44+
...shared,
45+
mode: 'production',
46+
devtool: 'source-map'
47+
}
48+
49+
module.exports = process.env.NODE_ENV === 'dev' ? dev : prod

0 commit comments

Comments
 (0)