From 96ac1cd6fe7d70676fbd2919c643aebcd83bc493 Mon Sep 17 00:00:00 2001 From: Bojan Hribernik Date: Tue, 16 Aug 2016 07:47:03 +0200 Subject: [PATCH] fix: Create commonjs, es and umd builds --- .travis.yml | 2 ++ package.json | 24 +++++++++-------- webpack.config.js | 69 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6276265..6f9615f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/package.json b/package.json index 2b6627e..5c1536a 100644 --- a/package.json +++ b/package.json @@ -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'", @@ -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", @@ -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", diff --git a/webpack.config.js b/webpack.config.js index f16f771..4ff80a9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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