Skip to content

WIP - Use Pundle as the module bundler #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/babel.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

module.exports = {
babelrc: false,
cacheDirectory: true,
presets: [
'babel-preset-es2015',
'babel-preset-es2016',
Expand Down
103 changes: 0 additions & 103 deletions config/webpack.config.dev.js

This file was deleted.

144 changes: 0 additions & 144 deletions config/webpack.config.prod.js

This file was deleted.

19 changes: 5 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"autoprefixer": "6.3.7",
"babel-core": "6.11.4",
"babel-eslint": "6.1.2",
"babel-loader": "6.2.4",
"babel-plugin-syntax-trailing-function-commas": "6.8.0",
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-object-rest-spread": "6.8.0",
Expand All @@ -39,32 +38,24 @@
"babel-preset-es2015": "6.9.0",
"babel-preset-es2016": "6.11.3",
"babel-preset-react": "6.11.1",
"babel-pundle": "1.0.0",
"babel-runtime": "6.11.6",
"chalk": "1.1.3",
"cross-spawn": "4.0.0",
"css-loader": "0.23.1",
"detect-port": "0.1.4",
"eslint": "3.1.1",
"eslint-loader": "1.4.1",
"eslint-plugin-flow-vars": "0.5.0",
"eslint-plugin-import": "1.12.0",
"eslint-plugin-jsx-a11y": "2.0.1",
"eslint-plugin-react": "5.2.2",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.9.0",
"filesize": "3.3.0",
"fs-extra": "0.30.0",
"gzip-size": "3.0.0",
"html-webpack-plugin": "2.22.0",
"json-loader": "0.5.4",
"mkdirp": "^0.5.1",
"opn": "4.0.2",
"postcss-loader": "0.9.1",
"process-bootstrap": "1.0.0",
"promise": "7.1.1",
"pundle": "1.1.0",
"pundle-dev": "1.1.0",
"rimraf": "2.5.4",
"style-loader": "0.13.1",
"url-loader": "0.5.7",
"webpack": "1.13.1",
"webpack-dev-server": "1.14.1",
"whatwg-fetch": "1.0.0"
},
"devDependencies": {
Expand Down
65 changes: 41 additions & 24 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,50 @@
process.env.NODE_ENV = 'production';

var fs = require('fs');
var filesize = require('filesize');
var gzipSize = require('gzip-size');
var path = require('path');
var mkdirp = require('mkdirp')
var Pundle = require('pundle')
var rimrafSync = require('rimraf').sync;
var webpack = require('webpack');
var config = require('../config/webpack.config.prod');
var paths = require('../config/paths');

// Remove all content but keep the directory so that
// if you're in it, you don't end up in Trash
rimrafSync(paths.appBuild + '/*');

function logBuildSize(assets, extension) {
for (var i = 0; i < assets.length; i++) {
var asset = assets[i];
if (asset.name.endsWith('.' + extension)) {
var fileContents = fs.readFileSync(paths.appBuild + '/' + asset.name);
console.log('Size (gzipped) of ' + asset.name + ': ' + filesize(gzipSize.sync(fileContents)));
}
}
}

webpack(config).run(function(err, stats) {
if (err) {
console.error('Failed to create a production build. Reason:');
console.error(err.message || err);
process.exit(1);
}
var pundle = new Pundle({
entry: [require.resolve('../config/polyfills'), 'index.js'],
rootDirectory: path.normalize(path.join(__dirname, '../template/src')),
pathType: 'filePath',
moduleDirectories: ['node_modules'],
})

pundle.loadPlugins([
[require.resolve('babel-pundle'), {
config: require('../config/babel.prod'),
}],
]).then(function() {
return pundle.compile()
}).then(function() {
return new Promise(function(resolve, reject) {
mkdirp(paths.appBuild, function(error) {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}).then(function() {
return new Promise(function(resolve, reject) {
fs.writeFile(path.join(paths.appBuild, 'bundle.js'), pundle.generate().contents, function(error) {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}).then(function() {
var openCommand = process.platform === 'win32' ? 'start' : 'open';
var homepagePath = require(paths.appPackageJson).homepage;
console.log('Successfully generated a bundle in the build folder!');
Expand All @@ -61,9 +77,10 @@ webpack(config).run(function(err, stats) {
console.log(' pushstate-server build');
console.log(' ' + openCommand + ' http://localhost:9000');
console.log();
var assets = stats.toJson()['assets'];
logBuildSize(assets, 'js');
logBuildSize(assets, 'css');
}
console.log('The bundle is optimized and ready to be deployed to production.');
});
}, function(err) {
console.error('Failed to create a production build. Reason:');
console.error(err.message || err);
process.exitCode = 1
})
Loading