Speed up build (#1852)

* single build webpack

* fix demo shell test
This commit is contained in:
Eugenio Romano
2017-05-03 13:01:00 +02:00
committed by Eugenio Romano
parent 8959476941
commit 0b246b8211
362 changed files with 2684 additions and 13104 deletions

View File

@@ -0,0 +1,14 @@
@license
Copyright 2016 Alfresco Software, Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,118 @@
{
"rules": {
"align": [
true,
"parameters",
"statements"
],
"ban": false,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"eofline": true,
"forin": true,
"indent": [
true,
"spaces"
],
"interface-name": false,
"jsdoc-format": true,
"label-position": true,
"max-line-length": [
true,
180
],
"member-ordering": [
true,
"static-before-instance",
"variables-before-functions"
],
"no-any": false,
"no-arg": true,
"no-bitwise": false,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-constructor-vars": false,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-eval": true,
"no-inferrable-types": false,
"no-internal-module": true,
"no-require-imports": false,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-unused-variable": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"no-var-requires": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [
true,
"single",
"avoid-escape"
],
"radix": true,
"semicolon": true,
"switch-default": true,
"trailing-comma": [
true,
{
"multiline": "never",
"singleline": "never"
}
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef": false,
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"use-strict": false,
"variable-name": [
true,
"check-format",
"allow-leading-underscore",
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-operator",
"check-separator",
"check-type",
"check-module",
"check-decl"
]
}
}

View File

@@ -0,0 +1,70 @@
var path = require('path');
var loaderUtils = require('loader-utils');
module.exports = function(content) {
this.cacheable && this.cacheable();
if(!this.emitFile) throw new Error('emitFile is required from module system');
var query = loaderUtils.getOptions(this) || {};
var configKey = query.config || 'multiFileLoader';
var options = this.options[configKey] || {};
var config = {
publicPath: false,
useRelativePath: false,
name: '[hash].[ext]'
};
// options takes precedence over config
Object.keys(options).forEach(function(attr) {
config[attr] = options[attr];
});
// query takes precedence over config and options
Object.keys(query).forEach(function(attr) {
config[attr] = query[attr];
});
var context = config.context || this.options.context;
var url = loaderUtils.interpolateName(this, config.name, {
context: context,
content: content,
regExp: config.regExp
});
var path = loaderUtils.interpolateName(this, '[path]', {
context: context,
content: content,
regExp: config.regExp
});
var outputPath = '';
if (config.outputPath) {
outputPath = (
typeof config.outputPath === 'function'
? config.outputPath(url, path)
: config.outputPath + url
);
} else {
outputPath = url;
}
var publicPath = JSON.stringify(url);
if (config.publicPath) {
publicPath = JSON.stringify(
typeof config.publicPath === 'function'
? config.publicPath(url, path)
: config.publicPath + url
);
}
publicPath = '__webpack_public_path__ + ' + publicPath;
if (query.emitFile === undefined || query.emitFile) {
this.emitFile(outputPath, content);
}
return 'module.exports = ' + publicPath + ';';
};
module.exports.raw = true;

View File

@@ -0,0 +1,10 @@
var path = require('path');
var _root = path.resolve(__dirname, '..');
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
}
exports.root = root;

View File

@@ -0,0 +1,114 @@
var webpackConfig = require('./webpack.test');
module.exports = function (config) {
var _config = {
basePath: '../' + config.component,
frameworks: ['jasmine-ajax', 'jasmine'],
files: [
'../node_modules/hammerjs/hammer.js',
//diagrams
'../node_modules/chart.js/dist/Chart.js',
'../node_modules/alfresco-js-api/dist/alfresco-js-api.js',
'../node_modules/raphael/raphael.js',
'../node_modules/moment/min/moment.min.js',
'../node_modules/md-date-time-picker/dist/js/mdDateTimePicker.js',
{pattern: '../node_modules/ng2-translate/**/*.js', included: false, watched: false},
{pattern: '../node_modules/ng2-charts/**/*.js', included: false, served: true, watched: false},
{pattern: '../node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false},
{pattern: '../node_modules/moment/**/*.js', included: false, served: true, watched: false},
// pdf-js
'../node_modules/pdfjs-dist/build/pdf.js',
'../node_modules/pdfjs-dist/build/pdf.worker.js',
'../node_modules/pdfjs-dist/web/pdf_viewer.js',
{pattern: 'karma-test-shim.js', watched: false},
{pattern: './src/assets/**/*.*', included: false, served: true, watched: false},
{pattern: './src/i18n/**/*.*', included: false, served: true, watched: false},
{pattern: './dist/**/*.js', included: false, served: true, watched: false},
{pattern: './dist/**/*.js.map', included: false, served: true, watched: false},
{pattern: './src/**/*.ts', included: false, served: true, watched: false}
],
client: {
component: config.component
},
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
port: 9876,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
colors: true,
autoWatch: true,
captureTimeout: 180000,
browserDisconnectTimeout: 180000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 300000,
browsers: ['Chrome'],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
// Karma plugins loaded
plugins: [
require('../node_modules/karma-jasmine'),
require('../node_modules/karma-coverage'),
require('../node_modules/karma-sourcemap-loader'),
require('../node_modules/karma-jasmine-ajax'),
require('../node_modules/karma-chrome-launcher'),
require('../node_modules/karma-mocha-reporter'),
require('../node_modules/karma-webpack'),
require('../node_modules/karma-jasmine-html-reporter')
],
webpackServer: {
noInfo: true
},
// Coverage reporter generates the coverage
reporters: ['mocha', 'coverage', 'kjhtml'],
preprocessors: {
'karma-test-shim.js': ['webpack', 'sourcemap'],
'./src/**/!(*spec|index|*mock|*model|*event).js': 'coverage'
},
coverageReporter: {
includeAllSources: true,
dir: '../' + config.component + '/coverage/',
subdir: 'report',
reporters: [
{type: 'text'},
{type: 'text-summary'},
{type: 'json', file: 'coverage-final.json'},
{type: 'html'},
{type: 'lcov'}
]
}
};
if (process.env.TRAVIS) {
config.browsers = ['Chrome_travis_ci'];
}
config.set(_config);
};

View File

@@ -0,0 +1,49 @@
const webpack = require("webpack");
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.common.js');
module.exports = webpackMerge(commonConfig, {
output: {
filename: '[name]/bundles/[name].js',
library: '[name]',
libraryTarget: 'umd',
chunkFilename: '[id].chunk.js'
},
entry: {
"ng2-alfresco-core": "./ng2-alfresco-core/index.ts",
"ng2-alfresco-datatable": "./ng2-alfresco-datatable/index.ts",
"ng2-activiti-diagrams": "./ng2-activiti-diagrams/index.ts",
"ng2-activiti-analytics": "./ng2-activiti-analytics/index.ts",
"ng2-activiti-form": "./ng2-activiti-form/index.ts",
"ng2-activiti-tasklist": "./ng2-activiti-tasklist/index.ts",
"ng2-activiti-processlist": "./ng2-activiti-processlist/index.ts",
"ng2-alfresco-documentlist": "./ng2-alfresco-documentlist/index.ts",
"ng2-alfresco-login": "./ng2-alfresco-login/index.ts",
"ng2-alfresco-search": "./ng2-alfresco-search/index.ts",
"ng2-alfresco-social": "./ng2-alfresco-social/index.ts",
"ng2-alfresco-tag": "./ng2-alfresco-tag/index.ts",
"ng2-alfresco-upload": "./ng2-alfresco-upload/index.ts",
"ng2-alfresco-viewer": "./ng2-alfresco-viewer/index.ts",
"ng2-alfresco-webscript": "./ng2-alfresco-webscript/index.ts",
"ng2-alfresco-userinfo": "./ng2-alfresco-userinfo/index.ts"
},
plugins: [
//new webpack.optimize.UglifyJsPlugin({
// mangle: {
// keep_fnames: true
// },
// compress: {
// warnings: false
// },
// output: {
// comments: false
// },
// sourceMap: true
//})
]
});

View File

@@ -0,0 +1,122 @@
const webpack = require('webpack');
const helpers = require('./helpers');
const fs = require('fs');
const path = require('path');
module.exports = {
resolveLoader: {
alias: {
"file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi")
}
},
// require those dependencies but don't bundle them
externals: [
/^\@angular\//,
/^rxjs\//,
'moment',
'ng2-charts',
'alfresco-js-api',
'ng2-alfresco-core',
'ng2-alfresco-datatable',
'ng2-activiti-analytics',
'ng2-activiti-diagrams',
'ng2-activiti-form',
"ng2-activiti-tasklist",
'ng2-alfresco-documentlist'
],
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
options: {
emitErrors: true,
configFile: path.resolve(__dirname, './assets/tslint.json')
},
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
enforce: 'pre',
test: /\.ts$/,
use: 'source-map-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.ts$/,
use: ['ts-loader', 'angular2-template-loader'],
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.css$/,
loader: ['to-string-loader', 'css-loader'],
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-multi-loader',
query: {
name: '[name].[hash].[ext]',
outputPath: (url, resourcePath)=> {
return resourcePath.replace('src', 'bundles') + url;
},
publicPath: (url, resourcePath)=> {
var component = resourcePath.substring(0, resourcePath.indexOf('src'));
var path = resourcePath.replace(component, '').replace('src', 'bundles');
return './' + path + url;
}
}
}
]
},
resolve: {
extensions: ['.ts', '.js'],
symlinks: false,
modules: [
'../ng2-components', 'node_modules'
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header.txt'), 'utf8')),
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('src'), // location of your src
{} // a map of your routes
),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
})
],
devtool: 'cheap-module-source-map',
node: {
fs: 'empty',
module: false
}
};

View File

@@ -0,0 +1,85 @@
const webpack = require('webpack');
const helpers = require('./helpers');
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
module.exports = {
module: {
rules: [
{
test: /\.ts$/,
loaders: ['ts-loader', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.css$/,
loader: ['to-string-loader', 'css-loader'],
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/,
loader: 'file-loader',
query: {
name: '[path][name].[ext]',
outputPath: (url)=> {
console.log
return url.replace('src', 'dist');
}
}
},
{
enforce: 'post',
test: /\.ts$/,
loader: 'istanbul-instrumenter-loader',
exclude: [
/node_modules/,
/test/,
/spec\.ts$/
]
}
]
},
resolve: {
extensions: ['.ts', '.js'],
symlinks: false,
modules: [
'../ng2-components', 'node_modules'
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('src'), // location of your src
{} // a map of your routes
),
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
})
],
devtool: 'inline-source-map',
node: {
fs: 'empty',
module: false
}
};