Skip to content

Commit

Permalink
Added yarn support & web pack compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
sunel committed Feb 5, 2017
1 parent ec206e1 commit 9322954
Show file tree
Hide file tree
Showing 5 changed files with 3,529 additions and 63 deletions.
28 changes: 15 additions & 13 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
var ora = require('ora'),
run = require('./theme').run;
run = require('./theme').run,
PrettyError = require('pretty-error'),
pe = new PrettyError();

var spinner = ora('building for production...')
var spinner = ora({
text: 'building for production...',
spinner: 'bouncingBar'
})
spinner.start()

run(function (err, stats) {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')
})
run().then(function(){
spinner.succeed()
})
.catch(function(error){
spinner.fail()
var renderedError = pe.render(error)
console.log(renderedError)
});
14 changes: 9 additions & 5 deletions build/config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var webpack = require('webpack');
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')

module.exports = {
entry: {
Expand All @@ -8,10 +9,10 @@ module.exports = {
filename: '[name].js'
},
module: {
loaders: [
rules: [
{
test: /\.css$/,
loaders: ['style', 'css']
test: /\.css$/,
loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
}
]
},
Expand All @@ -22,6 +23,9 @@ module.exports = {
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.CommonsChunkPlugin('common')
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor' // Specify the common bundle's name.
}),
new ExtractTextPlugin("[name].css")
]
};
67 changes: 42 additions & 25 deletions build/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,76 @@ var path = require('path'),
merge = require('webpack-merge'),
_ = require('lodash');
config = require('../config'),
assetpath = config.build.assetConfigPath;
assetpath = config.build.assetConfigPath
builderCounter = 0;

function readAssetConfig(assetpath){
try {
fs.statSync(assetpath)
return require(assetpath)
} catch (e) {
console.log("File does not exist.",assetpath)
console.log("run theme:compile to generate the file")
process.exit(-1);
throw new Error("Asset config File does not exist. \n" +
"Run theme:compile to generate the file");
}
}

function createWebpackComplier(options, callback) {
return webpack(options, callback)
return webpack(options, function(err, stats) {
if(err){callback(true, error);}
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n\n')
--builderCounter
if(builderCounter <= 0){
callback(false);
}
})
}

function genertareWebpackConfig(area, theme, asset, configs) {
function genertareWebpackConfig(area, theme, configs) {
var baseWebpackConfig = require('../config/webpack.config');
_.forOwn(configs, function(values, key) {
configs[key] = _.map(values, function(v) {
return 'theme/' + v;
})
})
baseWebpackConfig.entry = configs;
baseWebpackConfig.output.path = path.join(config.build.publicPath,area,theme,asset)
baseWebpackConfig.output.publicPath = path.join('assets',area,theme,asset)
baseWebpackConfig.resolve.alias.theme = path.join(config.build.resourcePath,area,theme,asset)

baseWebpackConfig.entry = configs;
baseWebpackConfig.output.path = path.join(config.build.publicPath,area,theme)
baseWebpackConfig.output.publicPath = path.join('assets',area,theme)

return baseWebpackConfig
}

function themeCompile(config, callback) {
const areas = config.areas;

function themeCompile(assetConfig, callback) {
const areas = assetConfig.areas;
const handles = assetConfig.handles;
_.forOwn(areas, function(themes, area) {
_.forOwn(themes, function(assets, theme) {
_.forOwn(assets, function(configs, asset) {
createWebpackComplier(genertareWebpackConfig(area, theme, asset, configs), callback)
})
const entries = _.zipObject(handles[area], _.map(handles[area]).map(function(val) {
return path.join(config.build.resourcePath,area,theme,'webpack', val+'.js');
}));
builderCounter++;
createWebpackComplier(genertareWebpackConfig(area, theme, entries), callback)
})
})
}

/**
* Runs the multiple webpack.
* @param {Function} [callback] A callback to be invoked once the build has
* been completed
* @return {Promise} A Promise that is resolved once all builds have been
* created
*/
function run(callback) {
themeCompile(readAssetConfig(assetpath), callback)
function run() {
return new Promise(function(resolve, reject) {
try {
themeCompile(readAssetConfig(assetpath), function (err, error) {
if(err) {reject(error)}
else {resolve()}
})
} catch(e) {
reject(e)
}
});
}

module.exports = {
Expand Down
44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@
"build": "node build/build.js"
},
"dependencies": {
"lodash": "^4.16.6",
"shelljs": "^0.7.4",
"vue": "^2.0.1"
"lodash": "^4.17.4",
"shelljs": "^0.7.6",
"vue": "^2.1.10"
},
"devDependencies": {
"autoprefixer": "^6.4.0",
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"babel-register": "^6.0.0",
"bluebird": "^3.4.6",
"css-loader": "^0.25.0",
"file-loader": "^0.9.0",
"autoprefixer": "^6.7.2",
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"bluebird": "^3.4.7",
"css-loader": "^0.26.1",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"file-loader": "^0.10.0",
"json-loader": "^0.5.4",
"ora": "^0.3.0",
"ora": "^1.1.0",
"pretty-error": "^2.0.2",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"vue-loader": "^9.4.0",
"vue-style-loader": "^1.0.0",
"webpack": "2.1.0-beta.25",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2",
"webpack-merge": "^0.14.1"
"vue-loader": "^10.3.0",
"vue-style-loader": "^2.0.0",
"vue-template-compiler": "^2.1.10",
"webpack": "^2.2.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.16.1",
"webpack-merge": "^2.6.1"
}
}
Loading

0 comments on commit 9322954

Please sign in to comment.