Last active
June 15, 2021 04:00
-
-
Save newcloudtech/b5001f993cb2e2974725ff58962bf01b to your computer and use it in GitHub Desktop.
Webpack and karma configs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpackConfig = require('../webpack.config.js'); | |
module.exports = function () { | |
autoWatch: true, | |
frameworks: ['jasmine'], | |
preprocessors: { | |
'../app/**/*.js': ['webpack'], | |
'../app/**/scripts/**/*.js': ['coverage'] | |
}, | |
webpack: { | |
resolve: webpackConfig.resolve, | |
module: _.extend({}, webpackConfig.module, { | |
loaders: [ | |
{ | |
test: /\.json$/, | |
loader: "json" | |
}, | |
{ | |
test: /\.s?css$/, | |
loader: 'ignore-loader' | |
}, | |
{ | |
test: /\.html$/, | |
loader: 'ignore-loader' | |
}], | |
postLoaders: [{ //delays coverage till tests are run, fixing transpiled source coverage error | |
test: /[^(\-spec)^(\-mock)]\.js$/, | |
exclude: /(node_modules)\//, | |
loader: "istanbul-instrumenter" | |
}] | |
}), | |
plugins: [ | |
new webpack.DefinePlugin(mockedConstants) | |
] | |
}, | |
webpackServer: { | |
noInfo: true //please don’t spam the console when running in karma! | |
}, | |
files: [ | |
'../node_modules/jquery/dist/jquery.js', | |
'../node_modules/jasmine-expect/dist/jasmine-matchers.js', | |
'../node_modules/angular/angular.js', | |
'../node_modules/angular-mocks/angular-mocks.js', | |
'../app/**/*-spec.js' | |
], | |
exclude: [], | |
reporters: ['progress', 'coverage'], | |
port: 8081, | |
browsers: ['PhantomJS'], | |
plugins: [ | |
require('karma-webpack'), | |
require("istanbul-instrumenter-loader"), | |
require('karma-phantomjs-launcher'), | |
require('karma-junit-reporter'), | |
require('karma-jasmine'), | |
require('karma-coverage') | |
], | |
coverageReporter: [ | |
{ | |
type: 'text-summary', | |
dir: 'coverage' | |
} | |
], | |
singleRun: false, | |
colors: true, | |
logLevel: config.LOG_INFO | |
};} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
var _ = require('lodash'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
var LicenseWebpackPlugin = require('license-webpack-plugin'); | |
var CSSExtractor = new ExtractTextPlugin('styles/[name].css', {allChunks: true}); | |
var SCSSExtractor = new ExtractTextPlugin('styles/[name].css', {allChunks: true}); | |
function getPlugins() { | |
var constants = { | |
build: require('config/constants'), | |
runtime: { | |
__DEBUG: !!env.DEBUG, | |
__METRICS: !!env.METRICS | |
} | |
}; | |
var plugins = [ | |
SCSSExtractor, | |
CSSExtractor, | |
new webpack.DefinePlugin(_.extend({}, constants.build, constants.runtime)), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendor', | |
chunks: ['app'], | |
filename: 'vendor.[hash].js', | |
minChunks: function minChunks(module) { | |
return module.resource | |
&& module.resource.indexOf('node_modules') > 0; | |
} | |
}), | |
new webpack.ProvidePlugin({ | |
$: 'jquery', | |
jQuery: 'jquery' | |
angular: 'angular' | |
}), | |
new HtmlWebpackPlugin(_.extend({ | |
chunks: ['app', 'vendor'], | |
inject: false, | |
template: 'app/index.html.template' | |
})) | |
]; | |
if (!!options.env.MINIFY) { | |
plugins.push(new webpack.optimize.UglifyJsPlugin()); | |
} | |
if (!!options.env.LICENSE) { | |
plugins.push(new LicenseWebpackPlugin({ | |
chunks: ['app', 'vendor'], | |
addLicenseText: false, | |
addUrl: true, | |
addUndefined: true, | |
filename: 'licenses.txt', | |
pattern: /^(.+)$/ | |
})); | |
} | |
return plugins; | |
} | |
function getScssLoader() { | |
var scssLoader = {test: /\.scss$/}; | |
var minify = !!process.env.MINIFY ? '?minimize' : ''; | |
if (!!process.env.HOT_RELOAD) { | |
scssLoader.loaders = ['style', 'css', 'sass']; | |
} else { | |
scssLoader.loader = SCSSExtractor.extract('style', `css${minify}!sass`); | |
} | |
return scssLoader; | |
} | |
module.exports = function () { | |
return { | |
resolve: { | |
root: [ | |
'app', | |
'common' | |
], | |
modulesDirectories: [ | |
'node_modules' | |
] | |
}, | |
resolveLoader: { | |
root: 'node_modules' | |
}, | |
output: { | |
path: '.tmp', | |
filename: '[name].bundle.[hash].js', | |
chunkFilename: '[name].bundle.[chunkhash].js' | |
}, | |
plugins: getPlugins(), | |
module: { | |
preLoaders: [ | |
{ | |
test: /\.js$/, | |
exclude: /(node_modules)/, | |
loader: 'babel', | |
query: { | |
presets: ['es2015'], | |
cacheDirectory: true | |
} | |
} | |
], | |
loaders: [ | |
getScssLoader(), | |
{ | |
test: /\.js$/, | |
exclude: /(node_modules)/, | |
loader: 'ng-annotate', | |
query: {add: true} | |
}, | |
{ | |
test: /\.json$/, | |
loader: 'json' | |
}, | |
{ | |
test: /\.css$/, | |
loader: CSSExtractor.extract('style', `css${process.env.MINIFY ? '?minimize' : ''}`) | |
}, | |
{ | |
test: /\.html$/, | |
include: ['app'], | |
loader: 'ngtemplate?relativeTo=app/!html' | |
}, | |
{ | |
include: ['common'], | |
test: /\.html$/, | |
loader: 'ngtemplate?relativeTo=common/!html' | |
} | |
] | |
}, | |
devtool: process.env.SOURCEMAPS ? 'eval' : 'hidden-source-map', | |
devServer: { | |
contentBase: '.tmp', | |
stats: { | |
timings: true, | |
chunkModules: false | |
} | |
}, | |
sassLoader: { | |
importer: require('node-sass-import-once'), | |
includePaths: [ | |
'common', | |
'node_modules', | |
'app', | |
require('node-bourbon').includePaths | |
], | |
precision: 10 | |
} | |
}; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment