Skip to content

Commit

Permalink
Implement node build
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelvalle committed Mar 2, 2017
1 parent 20c9eae commit 7af575e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
coverage
dist
*.log
.DS_Store
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"request",
"api"
],
"main": "dist/trae.min.js",
"module": "lib/index.js",
"main": "dist/trae.js",
"module": "dist/trae.min.js",
"author": "gillchristian <gillchristiang@gmail.com>",
"contributors": [
"ndelvalle <nicolas.delvalle@gmail.com>"
Expand All @@ -26,8 +26,10 @@
"scripts": {
"add": "all-contributors add",
"contributors": "all-contributors generate",
"build": "NODE_ENV=production rollup -c",
"build:dev": "rollup -c",
"build": "NODE_ENV=production npm run build:node && npm run build:browser",
"build:dev": "npm run build:node && npm run build:browser",
"build:node": "FORMAT=cjs rollup -c",
"build:browser": "FORMAT=umd rollup -c",
"build:dev:w": "rollup -c -w",
"build:docs": "npm run build && cp dist/trae.min.js docs/js/trae.min.js",
"docs": "http-server ./docs -o",
Expand Down Expand Up @@ -71,6 +73,8 @@
"rollup-plugin-conditional": "^1.1.1",
"rollup-plugin-eslint": "^3.0.0",
"rollup-plugin-filesize": "^1.0.1",
"rollup-plugin-node-builtins": "^2.1.0",
"rollup-plugin-node-globals": "^1.1.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.1",
Expand Down
37 changes: 24 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,64 @@ import filesize from 'rollup-plugin-filesize';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import visualizer from 'rollup-plugin-visualizer';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import skipCommentsCustom from './utils/uglify-skip-comments';

const pkg = require('./package.json');

const env = process.env.NODE_ENV || 'development';
const isProd = env === 'production';
const banner = `/**
const env = process.env.NODE_ENV || 'development';
const format = process.env.FORMAT || 'umd';
const isProd = env === 'production';
const isNodeEnv = format === 'cjs';
const banner = `/**
* Trae, the fetch library!
*
* @version: ${pkg.version}
* @authors: ${pkg.author} | ${pkg.contributors[0]}
*/`;

const generateDestName = () => {
if (isNodeEnv) { return 'dist/trae.js'; }
return isProd ? 'dist/trae.min.js' : 'dist/development.js';
};

export default {
entry : 'lib/index.js',
dest : isProd ? 'dist/trae.min.js' : 'dist/trae.js',
format : 'umd',
dest : generateDestName(),
moduleId : 'trae',
moduleName: 'trae',
sourceMap : !isProd && 'inline',
sourceMap : !isProd && !isNodeEnv && 'inline',
context : 'global',
format,
banner,
plugins: [
globals(),
builtins(),
eslint(),
resolve({
jsnext : true,
jsnext : !isNodeEnv,
main : true,
browser: true
browser: !isNodeEnv,
preferBuiltins: true
}),
commonjs({
namedExports: {
'node_modules/qs/lib/index.js': ['stringify']
// 'node_modules/whatwg-fetch/fetch.js': ['default']
}
}),
babel({
babelrc: false, // jest makes use of .babelrc
presets: ['es2015-rollup']
presets: ['es2015-rollup'],
exclude: 'node_modules/**'
}),
replace({
exclude : 'node_modules/**',
'process.env.NODE_ENV': JSON.stringify(env),
NODE_ENV : JSON.stringify(env)
}),
conditional({
condition: isProd,
plugin : uglify({ output: { comments: skipCommentsCustom } })
}),
conditional(isProd && !isNodeEnv, uglify({ output: { comments: skipCommentsCustom } })),
visualizer({ filename: './coverage/bundle-statistics.html' }),
filesize()
]
Expand Down

0 comments on commit 7af575e

Please sign in to comment.