Added angular-librarian for manage library

This commit is contained in:
Lorenzo Iovino 2017-11-14 11:07:08 +01:00
parent 9d174550f5
commit e625f9fd30
44 changed files with 1867 additions and 228 deletions

70
webpack/webpack.common.js Normal file
View file

@ -0,0 +1,70 @@
'use strict';
const fs = require('fs');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const ContextReplacementPlugin = webpack.ContextReplacementPlugin;
const LoaderOptionsPlugin = webpack.LoaderOptionsPlugin;
const webpackUtils = require('./webpack.utils');
const getCommonConfig = (type) => {
const tsconfigType = type !== 'dev' ? `.${ type }` : '';
return {
module: {
rules: [
{
exclude: /node_modules/,
test: /\.ts$/,
use: [
'awesome-typescript-loader?configFileName=' + webpackUtils.rootPath(`tsconfig${ tsconfigType }.json`),
'angular2-template-loader?keepUrl=true'
]
},
{ test: /\.html$/, use: 'raw-loader' },
{
use: ['url-loader?limit=10000'],
test: /\.(woff2?|ttf|eot|svg|jpg|jpeg|json|gif|png)(\?v=\d+\.\d+\.\d+)?$/
}
]
},
performance: { hints: false },
plugins: [
new ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
__dirname
),
new LoaderOptionsPlugin({
debug: true,
options: {
emitErrors: true
}
}),
new ExtractTextPlugin("*.css")
],
resolve: {
extensions: [ '.js', '.ts' ],
modules: [ webpackUtils.rootPath('node_modules') ]
}
};
};
module.exports = (type, typeConfig) => {
const configs = [getCommonConfig(type), typeConfig];
const customConfigPath = webpackUtils.rootPath('configs', `webpack.${ type }.js`);
if (fs.existsSync(customConfigPath)) {
let customConfig = require(customConfigPath);
if (Object.prototype.toString.call(customConfig) === '[object Function]') {
customConfig = customConfig();
}
configs.push(customConfig);
}
return webpackMerge.apply(null, configs);
};

77
webpack/webpack.dev.js Normal file
View file

@ -0,0 +1,77 @@
'use strict';
const HtmlWebpack = require('html-webpack-plugin');
const webpack = require('webpack');
const ChunkWebpack = webpack.optimize.CommonsChunkPlugin;
const webpackCommon = require('./webpack.common');
const webpackUtils = require('./webpack.utils');
const entryPoints = [
'vendor',
'scripts',
'styles',
'app'
];
const examplePath = function examples() {
return webpackUtils.relayArguments(
webpackUtils.rootPath,
'examples',
arguments
);
};
module.exports = webpackCommon('dev', {
devServer: {
contentBase: webpackUtils.rootPath('dist'),
port: 9000
},
devtool: 'cheap-module-eval-source-map',
entry: {
app: [ examplePath('example.main') ],
scripts: [],
vendor: [ webpackUtils.srcPath('vendor') ],
styles: [ examplePath('styles.scss') ]
},
module: {
rules: webpackUtils.buildRules({
cssExtract: examplePath(),
sassLoader: examplePath('styles.scss')
}, {
include: examplePath(),
test: /styles\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
})
},
output: {
filename: '[name].bundle.js',
path: webpackUtils.rootPath('dist')
},
plugins: [
new ChunkWebpack({
filename: 'vendor.bundle.js',
minChunks: Infinity,
name: 'vendor'
}),
new HtmlWebpack({
// shameless/shamefully stolen from Angular CLI
chunksSortMode: function(left, right) {
const leftIndex = entryPoints.indexOf(left.names[0]);
const rightIndex = entryPoints.indexOf(right.names[0]);
let direction = 0;
if (leftIndex > rightIndex) {
direction = 1;
} else if (leftIndex < rightIndex) {
direction = -1;
}
return direction;
},
filename: 'index.html',
inject: 'body',
template: examplePath('index.html')
})
]
});

46
webpack/webpack.test.js Normal file
View file

@ -0,0 +1,46 @@
'use strict';
const webpack = require('webpack');
const SourceMapDevToolPlugin = webpack.SourceMapDevToolPlugin;
const webpackCommon = require('./webpack.common');
const webpackUtils = require('./webpack.utils');
module.exports = (watch) => {
return webpackCommon('test', {
devtool: watch ? 'inline-source-map' : 'cheap-module-eval-source-map',
module: {
rules: [
{
test: /\.s?css$/,
use: ['raw-loader', 'css-loader', 'sass-loader']
},
{
enforce: 'pre',
exclude: /node_modules/,
test: /\.ts$/,
use: 'tslint-loader'
},
{
enforce: 'post',
exclude: [
/node_modules/,
/\.(e2e|spec\.)ts$/
],
test: /\.ts$/,
use: 'istanbul-instrumenter-loader?esModules=true'
}
]
},
plugins: [
new SourceMapDevToolPlugin({
filename: null,
test: /\.ts$/
})
],
resolve: {
modules: [ webpackUtils.srcPath() ],
moduleExtensions: ['-loader']
}
});
};

66
webpack/webpack.utils.js Normal file
View file

@ -0,0 +1,66 @@
'use strict';
const ExtractText = require('extract-text-webpack-plugin');
const path = require('path');
function rootPath() {
const rootDir = path.resolve(__dirname, '..');
return relayArguments(path.resolve, rootDir, arguments);
}
exports.rootPath = rootPath;
function srcPath() {
return relayArguments(rootPath, 'src', arguments);
};
exports.srcPath = srcPath;
function relayArguments(method, prefix, args) {
const fullArguments = [prefix].concat(
Array.prototype.slice.apply(args)
);
return method.apply(null, fullArguments);
}
exports.relayArguments = relayArguments;
exports.buildRules = (excludes, extraRules) => {
let cssExtractExcludes = [srcPath()];
let sassLoaderExcludes = [/node_modules/];
let rules;
excludes = excludes || {};
if (excludes.cssExtract) {
cssExtractExcludes = cssExtractExcludes.concat(excludes.cssExtract);
}
if (excludes.sassLoader) {
sassLoaderExcludes = sassLoaderExcludes.concat(excludes.sassLoader);
}
rules = [
{
exclude: cssExtractExcludes,
test: /\.css$/,
use: ExtractText.extract({
fallback: 'style-loader',
use: 'css-loader?sourceMap'
})
},
{
exclude: /node_modules/,
test: /\.css$/,
use: ['css-to-string-loader', 'css-loader']
},
{
exclude: sassLoaderExcludes,
use: ['css-to-string-loader', 'css-loader', 'sass-loader'],
test: /\.scss$/
}
];
if (extraRules) {
rules = rules.concat(extraRules);
}
return rules;
};