Skip to content
Merged
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
12 changes: 12 additions & 0 deletions config/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
enforce: 'post',
test: /\.js$/,
exclude: /node_modules\/(?!@nc)/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { useBuiltIns: 'usage', corejs: 3 }]],
plugins: ['@babel/plugin-transform-runtime', '@babel/plugin-proposal-object-rest-spread']
}
}
};
17 changes: 17 additions & 0 deletions config/clientlibs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
clientLibs generation configuration
All other configurations
*/

// Override all clientlibs
const override = false;

// array of categories to skip (if override is true)
const skipCategories = ['myproject.author'];
// extra XML params to append to .content.xml use key=value
// linter disabled since we are requirement to send $\{ to a template string

module.exports = {
override,
skipCategories
};
12 changes: 12 additions & 0 deletions config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
options: {
cache: true,
failOnError: true
}
}
};
122 changes: 122 additions & 0 deletions config/general.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const path = require('path');
const getArgumentValue = require('../utils/getArgumentValue');
/*

paths configurations

*/
// Project key for prefix and folders
const projectKey = 'myproj';

// root path of the package
const rootPath = path.resolve('../');

// source files path
const sourcesPath = path.join(rootPath, 'src/main/frontend/myproj');

// common folder for alias like import 'commons/utils/myFn';
const common = path.join(sourcesPath, 'common');

// paths that should be excluded from any search (defaults ones)
const ignore = ['!(**/target/**)', '!(**/jcr_root/**)', '!(**/common/**)'];

// where files should be compiled at
const destinationPath = path.join(rootPath, 'src/main/jcr_root/apps/myproj/clientlibs');

// Node modules for alias lower case for
const nodeModules = path.join(rootPath, 'build/node_modules');

/*

files entries configurations

*/
// what is the source files key sufix to compile
const sourceKey = 'clientlibs';

// what is the compiled bundle key
const bundleKey = 'bundle';

// source file types ['js', 'scss']
const sourceTypes = ['js', 'scss'];

// project local configutaions for subfolders so it compile as a bundle
const extendConfigurations = '.febuild';

// default tasks to run
// optional clientlibs
const defaultTasks = ['styles', 'webpack', 'clientlibs'];

/*

command line arguments configurations

*/
// By default its production, then use the flag or node env to change it
const isProduction = !(process.env.NODE_ENV === 'development')
&& !getArgumentValue('--development');

// Mode is string format
const mode = isProduction ? 'production' : 'development';

// check watchers flag
const watch = getArgumentValue('--watch');

// bundle analyse flag
const analyse = getArgumentValue('--analyse');

// task to execute via command line
const task = getArgumentValue('--task=');

// select config path params command line
const configFile = getArgumentValue('--config-file=');

// quiet
const quiet = getArgumentValue('--quiet');

// analyzerPort
const analyzerPort = getArgumentValue('--port=') || 8888;


// general webpack
const devtool = isProduction ? 'none' : 'inline-source-map';
// general optimization
const excludedFromVendors = ['@nc', 'babel', 'core-js'];

/*
flatten config + webpack options like what configs are modules.rules
*/

// modules to run on webpack rules (each config module.config.js)
const modules = ['eslint', 'babel'];

// split all entries
const multiple = true;

// export as a hole object
module.exports = {
projectKey,
sourceKey,
bundleKey,
sourceTypes,
rootPath,
sourcesPath,
common,
ignore,
destinationPath,
isProduction,
mode,
watch,
analyse,
analyzerPort,
task,
quiet,
configFile,
extendConfigurations,
modules,
multiple,
nodeModules,
defaultTasks,
devtool,
excludedFromVendors
};
29 changes: 29 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const general = require('./general.config.js');
const plugins = require('./plugins.config');
const eslint = require('./eslint.config');
const babel = require('./babel.config');
const output = require('./output.config');
const optimization = require('./optimization.config');
const clientlibs = require('./clientlibs.config');
const sass = require('./sass.config');
const stylelint = require('./stylelint.config');
const resolve = require('./resolve.config');
const postcss = require('./postcss.config');
const templates = require('./templates.config');
const modules = general.modules;

module.exports = {
general,
output,
optimization,
plugins,
eslint,
babel,
modules,
sass,
clientlibs,
stylelint,
resolve,
postcss,
templates
};
27 changes: 27 additions & 0 deletions config/optimization.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { isProduction, excludedFromVendors } = require('./general.config');
const moduleIsVendor = require('../utils/moduleIsVendor');

module.exports = {
minimize: isProduction,
usedExports: isProduction,
splitChunks: {
cacheGroups: {
// this treeshake vendors (but keep unique vendors at the clientlibs it belongs )
vendors: {
test: mod => moduleIsVendor(mod.context, excludedFromVendors),
name: 'commons/vendors.bundle.js',
chunks: 'all',
// used on at least 2 module
minChunks: 2
},
// this treeshakes common imports, if are and more than 2 clientlibs
treeshaking: {
test: mod => !moduleIsVendor(mod.context, excludedFromVendors),
name: 'commons/treeshaking.bundle.js',
chunks: 'all',
// used on at least 2 module
minChunks: 2
}
}
}
};
9 changes: 9 additions & 0 deletions config/output.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('./general.config').destinationPath;

module.exports = {
path,
filename: '[name]',
chunkFilename: '[name]',
publicPath: '/',
pathinfo: false
};
24 changes: 24 additions & 0 deletions config/plugins.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const webpack = require('webpack');

const { mode, analyse, analyzerPort } = require('./general.config');

// pass the mode foward
const enviroment = new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(mode)
});

// default plugins
const plugins = [enviroment];

// check each files / dependencies sizes
// src https://www.npmjs.com/package/webpack-bundle-analyzer
if (analyse) {
const BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const analyzer = new BundleAnalyzer({
analyzerPort
});

plugins.push(analyzer);
}

module.exports = plugins;
7 changes: 7 additions & 0 deletions config/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// postcss plugins to run
const plugins = ['autoprefixer'];

// break the build or not?
const failOnError = true;

module.exports = { plugins, failOnError };
15 changes: 15 additions & 0 deletions config/resolve.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');

const {
common,
sourcesPath,
nodeModules
} = require('./general.config');

module.exports = {
alias: {
utils: path.join(common, 'script/utils'),
hecore: sourcesPath
},
modules: [nodeModules]
};
10 changes: 10 additions & 0 deletions config/sass.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');
const { isProduction, common, nodeModules } = require('./general.config');

const includePaths = [path.join(common, 'styles'), nodeModules];
const outputStyle = isProduction ? 'compressed' : 'expanded';

module.exports = {
includePaths,
outputStyle
};
7 changes: 7 additions & 0 deletions config/stylelint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// sintax to validated
const sintax = 'scss';

// break the build or not?
const failOnError = true;

module.exports = { sintax, failOnError };
11 changes: 11 additions & 0 deletions config/templates.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

const clientlibTemplate = (category, prefix) => `<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
allowProxy="{Boolean}true"
categories="[${prefix}.${category}]"/>
`;

module.exports = {
clientlibTemplate
};
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./tasks/run');
Loading