Skip to content

Commit ca665e1

Browse files
author
Thomas Bolis
committed
Changing the build way and bundling fabric dependency to library
1 parent 7e448c5 commit ca665e1

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
before_install:
22
- sudo apt-get -qq update
33
- sudo apt-get install -y libcairo2-dev libjpeg-dev libgif-dev npm nodejs libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
4+
- sudo npm -g update npm
45

56
language: node_js
67
node_js:

examples/main.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import DownloadIcon from 'material-ui/lib/svg-icons/file/file-download';
2525
import dataJson from './data.json'
2626
import dataUrl from './data.url'
2727

28-
import Tools from '../src/tools';
29-
import SketchField from '../src/SketchField';
28+
//import Tools from '../src/tools';
29+
//import SketchField from '../src/SketchField';
30+
import {SketchField, Tools} from '../lib';
3031

3132
const styles = {
3233
root: {

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"scripts": {
2626
"clean": "rimraf lib && rimraf build",
2727
"prebuild": "rimraf lib",
28-
"build": "babel ./src --out-dir ./lib",
28+
"build": "webpack --config webpack.library.cfg.js --display-modules",
29+
"build:light": "babel ./src --out-dir ./lib",
2930
"build:examples": "webpack --config webpack.examples.cfg.js",
3031
"prepublish": "npm run test && npm run build",
3132
"lint": "eslint ./src",
@@ -50,8 +51,8 @@
5051
"eslint": "^1.2.1",
5152
"eslint-loader": "^1.0.0",
5253
"eslint-plugin-react": "^3.3.0",
54+
"fabric": "^1.5.0",
5355
"flexboxgrid": "^6.3.0",
54-
"formsy-react": ">=0.17.0 <1",
5556
"html-webpack-plugin": "^1.7.0",
5657
"karma": "^0.13.19",
5758
"karma-babel-preprocessor": "^6.0.1",
@@ -79,8 +80,5 @@
7980
"style-loader": "^0.13.0",
8081
"webpack": "^1.12.11",
8182
"webpack-dev-server": "^1.14.1"
82-
},
83-
"dependencies": {
84-
"fabric": "^1.5.0"
8583
}
8684
}

webpack.library.cfg.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
var path = require('path');
2+
3+
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
4+
const DefinePlugin = require('webpack/lib/DefinePlugin');
5+
const NoErrorsPlugin = require('webpack/lib/NoErrorsPlugin');
6+
const DedupePlugin = require('webpack/lib/optimize/DedupePlugin');
7+
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
8+
const OccurenceOrderPlugin = require('webpack/lib/optimize/OccurenceOrderPlugin');
9+
const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');
10+
const AggressiveMergingPlugin = require('webpack/lib/optimize/AggressiveMergingPlugin');
11+
12+
const srcPath = path.join(__dirname, 'src');
13+
14+
function containsObject(obj, list) {
15+
var i;
16+
for (i = 0; i < list.length; i++) {
17+
if (list[i] === obj) {
18+
return true;
19+
}
20+
}
21+
return false;
22+
}
23+
24+
const externals = [];
25+
const explicitExternals = [];
26+
const internals = ['fabric', 'canvas'];
27+
Object.keys(require('./package.json').devDependencies).forEach(function (k) {
28+
if (!containsObject(k, internals)) externals.push(k);
29+
});
30+
31+
module.exports = {
32+
entry: {
33+
src: './src'
34+
},
35+
output: {
36+
path: path.join(__dirname, 'lib'),
37+
filename: 'index.js',
38+
libraryTarget: 'umd'
39+
},
40+
//Every non-relative module is external apart from those given.
41+
//externals: [/^(?!fabric|canvas|base64-js|ieee754|isarray|jsdom|xmldom)[a-z\-0-9]+$/],
42+
externals: explicitExternals.concat(externals),
43+
resolve: {
44+
extensions: ['', '.js', '.jsx']
45+
},
46+
debug: false,
47+
cache: true,
48+
module: {
49+
loaders: [
50+
{
51+
test: /\.(js|jsx)$/,
52+
include: [srcPath],
53+
exclude: /(node_modules|bower_components|lib)/,
54+
loaders: ['babel']
55+
}
56+
]
57+
},
58+
plugins: [
59+
// minify on production
60+
new DedupePlugin(),
61+
new UglifyJsPlugin({
62+
compress: {
63+
warnings: false
64+
}
65+
}),
66+
new OccurenceOrderPlugin(),
67+
new AggressiveMergingPlugin(),
68+
new IgnorePlugin(new RegExp('^(fs|ipc)$')),
69+
new DefinePlugin({'process.env.NODE_ENV': '"production"'}),
70+
new HotModuleReplacementPlugin(),
71+
new NoErrorsPlugin()
72+
]
73+
};

0 commit comments

Comments
 (0)