Skip to content

Commit

Permalink
Build standalone to dist (closes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanem committed Dec 29, 2015
1 parent 1370878 commit 1fea6e1
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 18 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,2 +1,3 @@
coverage/
dist/
lib/
9 changes: 9 additions & 0 deletions bin/.eslintrc
@@ -0,0 +1,9 @@
{
"env": {
"shelljs": true
},
"rules": {
"no-console": 0,
"no-var": 0
}
}
39 changes: 39 additions & 0 deletions bin/prepublish.js
@@ -0,0 +1,39 @@
import 'shelljs/global';
config.fatal = true;

import path from 'path';
import fs from 'fs';
import semver from 'semver';
import packageJSON from '../package.json';

const [ , , newVersion] = process.argv;
const newSemver = getNewSemver(packageJSON.version, newVersion);

exec('npm run test:local');
exec('npm run build');

writePackageJSONVersion(newSemver);

exec('git add -A');
exec(`git commit -am "Release v${newSemver}"`);
exec(`git tag v${newSemver}`);
exec('git push');
exec('git push --tags');

function getNewSemver(currentVersion, newVersion) {
let newSemver = semver.valid(newVersion);
if (!newSemver) newSemver = semver.inc(currentVersion, newVersion);
if (!newSemver) {
echo('Invalid new version');
exit(1);
}
return newSemver;
}

function writePackageJSONVersion(newSemver) {
packageJSON.version = newSemver;
fs.writeFileSync(
path.join(process.cwd(), 'package.json'),
JSON.stringify(packageJSON, null, 2)
);
}
12 changes: 12 additions & 0 deletions bin/start.js
@@ -0,0 +1,12 @@
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import config from '../webpack.config.dev';

const devServerConfig = config.devServer;
const { port, hostname } = devServerConfig;

new WebpackDevServer(webpack(config), devServerConfig)
.listen(port, hostname, (err) => {
if (err) console.log(err);
console.log(`Listening at localhost:${port}`);
});
File renamed without changes.
File renamed without changes.
19 changes: 13 additions & 6 deletions package.json
Expand Up @@ -28,12 +28,17 @@
"table"
],
"scripts": {
"clean": "rimraf lib",
"build:lib": "babel src -d lib",
"build:umd": "webpack --config webpack.config.umd.js",
"build:umd:min": "webpack --config webpack.config.umd-min.js",
"build": "npm run clean:build && npm run build:lib && npm run build:umd && npm run build:umd:min",
"clean:build": "rimraf dist lib",
"clean:cov": "rimraf coverage",
"lint": "eslint .",
"test:local": "karma start karma.conf.js",
"test": "karma start karma.conf-ci.js",
"start": "node server.js",
"prepublish": "in-publish && npm run lint && npm run clean && babel src -d lib || not-in-publish"
"prepublish": "in-publish && babel-node bin/prepublish || not-in-publish",
"start": "babel-node bin/start.js",
"test": "npm run lint && npm run clean:cov && karma start karma.config.ci.js",
"test:local": "npm run lint && npm run clean:cov && karma start karma.config.local.js"
},
"devDependencies": {
"babel-cli": "^6.3.17",
Expand Down Expand Up @@ -73,6 +78,8 @@
"react-hot-loader": "^1.3.0",
"rimraf": "^2.5.0",
"sass-loader": "^3.1.2",
"semver": "^5.1.0",
"shelljs": "^0.5.3",
"style-loader": "^0.13.0",
"webpack": "^1.12.9",
"webpack-dev-middleware": "^1.4.0",
Expand All @@ -86,4 +93,4 @@
"clamp": "^1.0.1",
"lodash.isfunction": "^3.0.6"
}
}
}
12 changes: 0 additions & 12 deletions server.js

This file was deleted.

File renamed without changes.
22 changes: 22 additions & 0 deletions webpack.config.umd-min.js
@@ -0,0 +1,22 @@
/*eslint no-var: 0*/

var webpack = require('webpack');

var config = Object.create(require('./webpack.config.umd'));

config.output.filename = 'Salvager.min.js';

config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false
}
})
];

module.exports = config;
48 changes: 48 additions & 0 deletions webpack.config.umd.js
@@ -0,0 +1,48 @@
/*eslint no-var: 0*/

var webpack = require('webpack');

module.exports = {

entry: './src/Salvager.js',

externals: {
react: {
root: 'React',
commonjs: 'react',
commonjs2: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom'
}
},

module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}
]
},

output: {
library: 'Salvager',
libraryTarget: 'umd',
path: 'dist',
filename: 'Salvager.js'
},

plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
]

};

0 comments on commit 1fea6e1

Please sign in to comment.