Skip to content

Instantly share code, notes, and snippets.

@Calamari
Last active August 25, 2016 16:48
Show Gist options
  • Save Calamari/5badf16d135754d0842ee9eed4948514 to your computer and use it in GitHub Desktop.
Save Calamari/5badf16d135754d0842ee9eed4948514 to your computer and use it in GitHub Desktop.
Webpack, Karma, jasmine, react Boilerplate
{
"presets": ["es2015", "react"],
"plugins": [
"add-module-exports",
"transform-object-rest-spread",
"transform-class-properties",
"transform-flow-strip-types"
]
}
/* eslint-disable */
module.exports = {
"extends": "airbnb",
// used for flowtype
"parser": "babel-eslint",
"parserOptions": {
"ignorePattern": ".eslintrc.js",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"globals": {},
"rules": {
"comma-dangle": 0,
"no-underscore-dangle": 0,
"max-len": [0, 140],
// Fires on none react files as well, where we not need it
"react/jsx-no-bind": 0
}
}
[ignore]
.*/node_modules/.*
npm install --save-dev webpack babel-loader babel-core babel-preset-es2015 babel-plugin-transform-runtime babel-plugin-transform-object-rest-spread react babel-preset-react babel-polyfill
# Install js testing using Karma
npm install --save-dev karma-babel-preprocessor karma-webpack karma-jasmine karma-chrome-launcher karma karma-cli babel-istanbul babel-istanbul-loader fstream-ignore karma-coverage karma-webpack karma-sourcemap-loader jasmine babel-plugin-add-module-exports deep-freeze
# When using flow type checking:
npm install --save-dev flow-bin babel-plugin-transform-flow-strip-types eslint-plugin-flowtype babel-plugin-transform-class-properties
# Installing react and redux
npm install --save-dev react-dom react-redux redux
# If we want to have eslinting
npm install --save-dev eslint babel-eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react
# Create js app source and test dirs
mkdir -p js_app/__tests__
# Create js output dir
mkdir -p public/a/
# Create starting file
touch js_app/index.js
# Create according test file
touch js_app/__tests__/index-test.js
# Config file for flow
touch .flowconfig
var path = require('path');
module.exports = function (config) {
config.set({
browsers: ['Chrome'],
coverageReporter: {
reporters: [
{ type: 'html', subdir: 'html' },
{ type: 'lcovonly', subdir: '.' },
],
},
files: [
'tests.webpack.js',
],
frameworks: [
'jasmine',
],
preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap'],
},
reporters: ['progress', 'coverage'],
webpack: {
cache: true,
devtool: 'inline-source-map',
module: {
preLoaders: [
{
test: /-test\.js$/,
include: /js_app/,
exclude: /(bower_components|node_modules)/,
loader: 'babel',
query: {
cacheDirectory: true,
},
},
{
test: /\.js?$/,
include: /js_app/,
exclude: /(node_modules|bower_components|__tests__)/,
loader: 'babel-istanbul',
query: {
cacheDirectory: true,
},
},
],
loaders: [
{
test: /\.js$/,
include: path.resolve(__dirname, '../js_app'),
exclude: /(bower_components|node_modules|__tests__)/,
loader: 'babel',
query: {
cacheDirectory: true,
},
},
],
},
},
});
};
{
"scripts": {
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"test": "./node_modules/karma/bin/karma start karma.config.js"
}
}
var testsContext = require.context('./js_app', true, /-test\.js$/);
testsContext.keys().forEach(testsContext);
var srcContext = require.context('./js_app', true, /^((?!__tests__).)*.js$/);
srcContext.keys().forEach(srcContext);
module.exports = {
entry: [
'babel-polyfill',
'./js_app/'
],
output: {
path: 'public/a/',
filename: 'app.js',
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.jsx?/,
loader: 'babel',
include: __dirname + '/js_app',
query: {
cacheDirectory: true
},
}
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment