Skip to content

Commit

Permalink
fix: Create commonjs, es and umd builds
Browse files Browse the repository at this point in the history
  • Loading branch information
HriBB committed Aug 16, 2016
1 parent eb29835 commit 96ac1cd
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ before_install:
- npm i -g npm@^2.0.0
before_script:
- npm prune
script:
- npm run build
after_success:
- npm run semantic-release
branches:
Expand Down
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"name": "react-mdl-selectfield",
"description": "React Material Design Lite Selectfield Component",
"main": "components/index.js",
"description": "React MDL SelectField Component",
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"scripts": {
"start": "npm run storybook",
"storybook": "cross-env NODE_ENV=development start-storybook -p 9002",
"dev": "cross-env NODE_ENV=development node ./server.js",
"lint": "eslint components/** test/**",
"build-examples": "cross-env NODE_ENV=production webpack --progress --verbose --colors",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --progress --verbose --colors",
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --progress --verbose --colors",
"build:examples": "cross-env BABEL_ENV=commonjs babel-node examples/buildAll.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
"lint": "eslint src/** test/**",
"prepublish": "npm run lint",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"test": "mocha --require test/config/setup 'test/*.js'",
Expand All @@ -34,10 +40,7 @@
"bugs": {
"url": "https://github.com/HriBB/react-mdl-selectfield/issues"
},
"homepage": "https://github.com/HriBB/react-mdl-selectfield",
"peerDependencies": {
"react-mdl": "^1.6.1"
},
"homepage": "https://hribb.github.io/react-mdl-selectfield/",
"devDependencies": {
"@kadira/storybook": "^1.41.0",
"autoprefixer": "^6.4.0",
Expand Down Expand Up @@ -80,8 +83,7 @@
"sinon": "^1.17.4",
"style-loader": "^0.13.0",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1",
"webpack-hot-middleware": "^2.12.2"
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"@kadira/storybook-deployer": "^1.0.0",
Expand Down
69 changes: 65 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
if (process.env.NODE_ENV === 'production') {
module.exports = require('./webpack.config.prod')
} else {
module.exports = require('./webpack.config.dev')
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

var env = process.env.NODE_ENV;
var suffix = env === 'production' ? '.min' : '';
var filename = `react-mdl-selectfield${suffix}`;

var config = {
entry: [
path.resolve(__dirname, 'src', 'index')
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: `${filename}.js`,
library: filename,
libraryTarget: 'umd'
},
resolve: {
extensions: ['', '.js']
},
module: {
preLoaders: [{
test: /\.js$/,
loader: 'eslint',
exclude: /node_modules/
}],
loaders: [{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},{
test: /\.(scss|css)$/,
loader: ExtractTextPlugin.extract('css!postcss!sass'),
}]
},
postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ],
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env)
}),
new ExtractTextPlugin(`${filename}.css`)
],
};

if (env === 'production') {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
}
})
)
}

module.exports = config

0 comments on commit 96ac1cd

Please sign in to comment.