Skip to content

Commit 67c38ca

Browse files
committed
reorg build process
1 parent a93ee40 commit 67c38ca

File tree

110 files changed

+11612
-3195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+11612
-3195
lines changed

.babelrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
"loose": [
44
"all"
55
],
6+
67
"blacklist": [
78
"es6.tailCall",
89
"es6.forOf",
910
"es7.trailingFunctionCommas",
1011
"es7.comprehensions",
1112
"es7.exportExtensions"
1213
],
13-
"plugins": ["babel-plugin-object-assign"]
14+
15+
"plugins": [
16+
"babel-plugin-object-assign"
17+
],
18+
"extra": {
19+
"externalHelperPlugin": {
20+
"path": "util/babelHelpers.js",
21+
"base": "src"
22+
}
23+
}
1424
}

build/babel.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var args = require('yargs').argv
2+
, babel = require('babel-core')
3+
, fs = require('fs')
4+
, outputFileSync = require('output-file-sync')
5+
, glob = require('glob')
6+
, path = require('path');
7+
8+
var helpers = []
9+
, babelrc = JSON.parse(
10+
fs.readFileSync(path.join(__dirname, '../.babelrc')));
11+
12+
args._.forEach(function (input) {
13+
var files = glob.sync(input + '/**/*.js*');
14+
if (!files.length) files = [input];
15+
16+
files.forEach(function(file){
17+
var relative = file.replace(/\.(\w*?)$/, '') + '.js'
18+
, dest = path.join(args.outDir, path.relative(input, relative))
19+
, data = babel.transformFileSync(file, {
20+
externalHelpers: true,
21+
plugins: [
22+
"babel-plugin-external-helpers:after"
23+
]
24+
});
25+
26+
outputFileSync(dest, data.code);
27+
28+
(data.metadata.usedHelpers || []).forEach(function(helper){
29+
if (helpers.indexOf(helper) === -1)
30+
helpers.push(helper)
31+
})
32+
33+
console.log(file + ' -> ' + dest);
34+
});
35+
36+
});
37+
38+
if (helpers.length) {
39+
var outHelper = path.join(args.outDir, babelrc.extra.externalHelperPlugin.path)
40+
console.log('outputing helper file: ', outHelper)
41+
outputFileSync(
42+
outHelper, babel.buildExternalHelpers(helpers, 'umd'))
43+
}

build/browser.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var path = require('path')
2+
, makeConfig = require('./make-config');
3+
4+
module.exports = makeConfig({
5+
6+
noCompile: true,
7+
8+
banner: true,
9+
10+
minimize: false,
11+
12+
entry: './lib/index.js',
13+
14+
output: {
15+
path: path.join(__dirname, '../dist'),
16+
filename: 'react-widgets.js',
17+
library: 'ReactWidgets',
18+
libraryTarget: 'umd'
19+
},
20+
21+
externals: {
22+
globalize: 'Globalize',
23+
'react-dom': {
24+
root: 'ReactDOM',
25+
commonjs: 'react-dom',
26+
commonjs2: 'react-dom'
27+
},
28+
react: {
29+
root: 'React',
30+
commonjs: 'react',
31+
commonjs2: 'react'
32+
}
33+
}
34+
})

build/dev.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var path = require('path')
2+
, makeConfig = require('./make-config');
3+
, args = require('yargs').argv;
4+
5+
module.exports = makeConfig({
6+
7+
hot: false,
8+
9+
production: false,
10+
11+
devtool: 'source-map',
12+
13+
entry: path.join(__dirname,'../dev/dev.jsx'),
14+
15+
output: {
16+
filename: 'bundle.js',
17+
path: __dirname
18+
}
19+
20+
})

build/docs.config.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var webpack = require('webpack')
2+
var path = require('path')
3+
var makeConfig = require('./make-config')
4+
var args = require('yargs').argv;
5+
6+
module.exports = makeConfig({
7+
8+
minimize: args.production,
9+
10+
devtool: args.production ? null : 'source-map',
11+
//hot: !args.production,
12+
13+
entry: {
14+
app: path.join(__dirname, '../docs/components/docs.jsx'),
15+
vendor: ['react', 'react-dom', 'globalize']
16+
},
17+
18+
output: {
19+
path: path.join(__dirname, '../docs/public'),
20+
filename: 'docs.js',
21+
publicPath: '/docs/public'
22+
},
23+
24+
externals: {
25+
'babel/browser': 'window.babel'
26+
},
27+
28+
plugins: [
29+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
30+
],
31+
32+
loaders: [
33+
{ test: /\.json$/, loader: 'json' },
34+
{ test: /\.raw$/, loader: 'raw' },
35+
{ test: /\.api\.md$/, loader: 'babel-loader!' + path.join(__dirname, '../docs/vendor/apiLoader') },
36+
{ test: /.md$/, loader: 'babel-loader!' + path.join(__dirname, '../docs/vendor/mdLoader'), exclude: /\.api\.md$/ }
37+
]
38+
})

build/make-config.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
var path = require('path')
2+
, webpack = require('webpack')
3+
, ExtractTextPlugin = require('extract-text-webpack-plugin')
4+
, pkg = require('../package.json');
5+
6+
module.exports = function makeConfig(options){
7+
var entry = options.entry
8+
, plugins = options.plugins || []
9+
10+
var loaders = [
11+
{ test: /\.css$/, loader: options.extractStyles
12+
? ExtractTextPlugin.extract('style-loader', 'css-loader')
13+
: 'style-loader!css-loader' },
14+
15+
{ test: /\.less$/, loader: options.extractStyles
16+
? ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader')
17+
: 'style-loader!css-loader!less-loader' },
18+
19+
{ test: /\.gif$/, loader: 'url-loader?mimetype=image/png' },
20+
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
21+
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader?name=[name].[ext]' }
22+
];
23+
24+
if (!options.noCompile)
25+
loaders.push(
26+
{ test: /\.jsx$|\.js$/, loader: 'babel-loader', exclude: /node_modules/ })
27+
28+
if (options.hot){
29+
loaders.splice(loaders.length - 1, 0,
30+
{ test: /\.jsx$|\.js$/, loader: 'react-hot-loader', exclude: /node_modules/ })
31+
32+
plugins.push(
33+
new webpack.HotModuleReplacementPlugin(),
34+
new webpack.NoErrorsPlugin())
35+
36+
entry = [
37+
'webpack-dev-server/client?http://localhost:8080',
38+
'webpack/hot/only-dev-server',
39+
entry
40+
]
41+
}
42+
43+
if (options.loaders)
44+
loaders = loaders.concat(options.loaders)
45+
46+
47+
48+
if (options.minimize)
49+
plugins.push(
50+
new webpack.optimize.UglifyJsPlugin({
51+
compress: { warnings: false, dead_code: true } //eslint-disable-line
52+
}),
53+
new webpack.optimize.DedupePlugin(),
54+
new webpack.NoErrorsPlugin())
55+
else
56+
plugins.push(
57+
new webpack.DefinePlugin({
58+
'__VERSION__': JSON.stringify(pkg.version)
59+
}));
60+
61+
if ( options.production || options.minimize )
62+
plugins.push(new webpack.DefinePlugin({
63+
'__VERSION__': JSON.stringify(pkg.version),
64+
'process.env': { NODE_ENV: JSON.stringify('production') }
65+
}))
66+
67+
if (options.extractStyles)
68+
plugins.push(
69+
new ExtractTextPlugin(options.styleName || 'styles.css', {
70+
allChunks: true
71+
}))
72+
73+
if (options.banner) {
74+
plugins.push(
75+
new webpack.BannerPlugin(
76+
'(c) ' + (new Date()).getFullYear() + ' Jason Quense | '
77+
+ 'https://github.com/jquense/react-widgets/blob/master/License.txt'
78+
, { entryOnly : true }))
79+
}
80+
81+
return {
82+
cache: true,
83+
84+
devtool: options.devtool,
85+
86+
entry: entry,
87+
88+
output: options.output,
89+
90+
externals: options.externals,
91+
92+
resolve: {
93+
extensions: ['', '.js', '.jsx'],
94+
alias: {
95+
'react-widgets': path.join(__dirname, '..', 'src')
96+
}
97+
},
98+
99+
module: {
100+
loaders: loaders
101+
},
102+
103+
plugins: plugins,
104+
105+
node: {
106+
Buffer: false
107+
}
108+
}
109+
}

build/test.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var makeConfig = require('./make-config');
2+
3+
module.exports = makeConfig({
4+
5+
devtool: 'inline-source-map',
6+
7+
loaders: [
8+
{ test: /sinon-chai/, loader: 'imports?define=>false' }
9+
]
10+
})

0 commit comments

Comments
 (0)