Commit 3451740b authored by Stanislav Fifik's avatar Stanislav Fifik

basic gulp for styleguide

parents
styleguide/demo/web
node_modules
.idea
*~
\ No newline at end of file
"use strict";
var source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
eventStream = require('event-stream'),
glob = require('glob'),
path = require('path'),
argv = require('yargs').argv,
exec = require('child_process').exec;
var gulp = require('gulp-help')(require('gulp'));
var $gulp = require('gulp-load-plugins')();
var $less = {
autoprefix: require('less-plugin-autoprefix'),
npmImport: require('less-plugin-npm-import'),
};
var webpack = require('webpack');
var $webpack = {
FriendlyErrorsWebpackPlugin: require('friendly-errors-webpack-plugin'),
ExtractTextPlugin: require('extract-text-webpack-plugin')
};
function generateEntries(ary) {
var entries = {};
for (let entryPath of ary) {
entries[path.parse(entryPath).name] = entryPath;
}
return entries;
}
module.exports = {
/**
* These npm modules should be transpiled with babel
*/
BABEL_NPM_MODULES: [
'*designeo*'
],
BABEL_CONFIG: {
presets: ['env'],
babelrc: false,
compact: false
},
gulp: gulp,
init: function(path){
this.gulpfilePath = path;
},
symfony: function(){
//this.js()
},
styleguide: function(){
this.js('js', glob.sync('./js/*.bundle.js'), './demo/web/js/');
this.cssWebpack('css', glob.sync('./demo/resources/less/main.less'), './demo/web/css/');
gulp.task('build', ['js', 'css']);
gulp.task('default', ['build']);
},
css: function(name, entryPoints, destination) {
gulp.task(name, 'Build css bundles from `css`', function() {
return gulp.src(entryPoints)
.pipe($gulp.plumber())
.pipe($gulp.if(!argv.production, $gulp.sourcemaps.init()))
.pipe($gulp.less({
plugins: [
new $less.autoprefix({browsers: ["last 2 versions"]}),
new $less.npmImport({
prefix: '~'
})
]
}))
.pipe($gulp.if(!argv.production, $gulp.sourcemaps.write('.')))
.pipe(gulp.dest(destination));
});
},
cssWebpack: function(name, entryPoints, destination) {
gulp.task(name, 'Build css bundles from `css`', function(callback) {
process.chdir(module.exports.gulpfilePath);
webpack({
entry: generateEntries(entryPoints),
devServer: { stats: "errors-only"},
amd: true,
output: {
path: path.resolve(module.exports.gulpfilePath, destination),
filename: '[name].css',
publicPath: '/css',
},
target: 'web',
watch: argv.watch,
module: {
loaders: [
// Extract css files
{
test: /\.css$/,
loader: $webpack.ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
},
// Optionally extract less files
// or any other compile-to-css language
{
test: /\.less$/,
loader: $webpack.ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader!less-loader'
})
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=10000&prefix=img'
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader?prefix=img/&limit=10000&minetype=application/font-woff"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader"
},
// You could also use other loaders the same way. I. e. the autoprefixer-loader
]
},
plugins: [
new $webpack.ExtractTextPlugin("[name].css"),
new $webpack.FriendlyErrorsWebpackPlugin({
clearConsole: false,
}),
]
}, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
if (!argv.watch) {
callback();
}
});
})
},
js: function(name, entryPoints, destination){
gulp.task(name, 'Build javascript bundles from `js`', function(callback){
process.chdir(module.exports.gulpfilePath);
webpack({
entry: generateEntries(entryPoints),
devServer: { stats: "errors-only"},
amd: true,
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': './js/'
}
},
output: {
path: path.resolve(module.exports.gulpfilePath, destination),
filename: '[name].js',
publicPath: '/js',
},
target: 'web',
watch: argv.watch,
module: {
rules: [
{
test: /\.js$/,
include: module.exports.BABEL_NPM_MODULES.map((lib) => new RegExp(`node_modules/${lib}`)),
use: {
loader: 'babel-loader',
options: module.exports.BABEL_CONFIG
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
css: {
loader: 'css-loader',
options: {
minimize: process.env.NODE_ENV === 'production',
sourceMap: !(process.env.NODE_ENV === 'production'),
}
}
}
}
},
]
},
plugins: [
new $webpack.FriendlyErrorsWebpackPlugin({
clearConsole: false,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(argv.production ? 'production' : 'development'),
'process.env.VUE_ENV': JSON.stringify('browser')
})
]
}, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
if (!argv.watch) {
callback();
}
});
});
}
};
\ No newline at end of file
{
"name": "designeo-gulp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-loader": "^7.0.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.4.0",
"babel-preset-latest": "^6.24.1",
"css-loader": "^0.28.2",
"event-stream": "^3.3.4",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.11.1",
"friendly-errors-webpack-plugin": "^1.6.1",
"gulp": "^3.9.1",
"gulp-help": "^1.6.1",
"gulp-if": "^2.0.2",
"gulp-less": "^3.3.0",
"gulp-load-plugins": "^1.5.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.6.0",
"gulp-util": "^3.0.8",
"less": "^2.7.2",
"less-loader": "^4.0.3",
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-npm-import": "^2.1.0",
"style-loader": "^0.18.1",
"url-loader": "^0.5.8",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"vue": "^2.0.0",
"vue-loader": "^12.0.4",
"vue-template-compiler": "^2.0.0",
"webpack": "^2.6.0",
"yargs": "^8.0.1"
}
}
@import "variables";
body {
background-color: @bg-color;
background-image: url(../images/test.png);
}
\ No newline at end of file
@bg-color: red;
\ No newline at end of file
var designeoGulp = require('../index.js');
console.log(__dirname);
designeoGulp.init(__dirname);
designeoGulp.styleguide();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment