update some things with the webpack config

This commit is contained in:
Kent C. Dodds 2016-05-23 19:49:35 -06:00
parent db9e4d8346
commit f9e9eac4a8
7 changed files with 39 additions and 40 deletions

View File

@ -3,7 +3,7 @@
"env": { "env": {
"test": { "test": {
"plugins": [ "plugins": [
["__coverage__", {"ignore": "test"}] ["__coverage__", {"ignore": "*.test.*"}]
] ]
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"extends": ["kentcdodds/es-next"], "extends": ["kentcdodds/es-next"],
"rules": { "rules": {
// these are only here because I didn't // these are only here because I did not
// want to update the entire codebase ¯\_(ツ)_/¯ // want to update the entire codebase ¯\_(ツ)_/¯
"func-names": 0, "func-names": 0,
"no-var": 0, "no-var": 0,
@ -10,5 +10,12 @@
"valid-jsdoc": 0, "valid-jsdoc": 0,
"vars-on-top": 0, "vars-on-top": 0,
"complexity": [2, 6], "complexity": [2, 6],
},
"globals": {
"jasmine": false,
"describe": false,
"it": false,
"beforeEach": false,
"expect": false,
} }
} }

View File

@ -1,14 +1,15 @@
const webpackConfig = require('./webpack.config') const webpackConfig = require('./webpack.config')({test: true})
process.env.BABEL_ENV = 'test' // so we load the correct babel plugins
require('babel-register') require('babel-register')
module.exports = function setKarmaConfig(config) { module.exports = function setKarmaConfig(config) {
config.set({ config.set({
basePath: '', basePath: '',
frameworks: ['jasmine'], frameworks: ['jasmine'],
files: ['test/**/*Spec.js'], files: ['src/**/*.test.js'],
exclude: [], exclude: [],
preprocessors: { preprocessors: {
'test/**/*Spec.js': ['webpack'], 'src/**/*.test.js': ['webpack'],
}, },
webpack: webpackConfig, webpack: webpackConfig,
webpackMiddleware: {noInfo: true}, webpackMiddleware: {noInfo: true},

View File

@ -13,7 +13,6 @@
"babel-preset-es2015-webpack": "6.4.1", "babel-preset-es2015-webpack": "6.4.1",
"babel-preset-stage-2": "6.5.0", "babel-preset-stage-2": "6.5.0",
"cpy-cli": "1.0.0", "cpy-cli": "1.0.0",
"cross-env": "1.0.7",
"css-loader": "0.23.1", "css-loader": "0.23.1",
"eslint": "2.9.0", "eslint": "2.9.0",
"eslint-config-kentcdodds": "6.2.1", "eslint-config-kentcdodds": "6.2.1",
@ -32,7 +31,7 @@
"style-loader": "0.13.1", "style-loader": "0.13.1",
"webpack": "2.1.0-beta.7", "webpack": "2.1.0-beta.7",
"webpack-dev-server": "2.0.0-beta", "webpack-dev-server": "2.0.0-beta",
"webpack-validator": "1.5.0" "webpack-validator": "2.1.0"
}, },
"config": { "config": {
"ghooks": { "ghooks": {
@ -40,20 +39,20 @@
} }
}, },
"scripts": { "scripts": {
"test": "cross-env NODE_ENV=test karma start", "test": "karma start",
"watch:test": "cross-env NODE_ENV=test karma start --auto-watch --no-single-run", "watch:test": "karma start --auto-watch --no-single-run",
"validate": "npm-run-all --parallel validate-webpack:* lint test", "validate": "npm-run-all --parallel validate-webpack:* lint test",
"validate-webpack:dev": "cross-env NODE_ENV=development webpack-validator webpack.config.js", "validate-webpack:dev": "webpack-validator webpack.config.js --env.dev",
"validate-webpack:prod": "cross-env NODE_ENV=production webpack-validator webpack.config.js", "validate-webpack:prod": "webpack-validator webpack.config.js --env.prod",
"clean-dist": "rimraf dist", "clean-dist": "rimraf dist",
"copy-files": "cpy src/index.html src/favicon.ico dist", "copy-files": "cpy src/index.html src/favicon.ico dist",
"clean-and-copy": "npm run clean-dist && npm run copy-files", "clean-and-copy": "npm run clean-dist && npm run copy-files",
"prestart": "npm run clean-and-copy", "prestart": "npm run clean-and-copy",
"start": "cross-env NODE_ENV=development webpack-dev-server --content-base dist", "start": "webpack-dev-server --env.dev --content-base dist",
"prebuild": "npm run clean-and-copy", "prebuild": "npm run clean-and-copy",
"prebuild:prod": "npm run clean-and-copy", "prebuild:prod": "npm run clean-and-copy",
"build": "cross-env NODE_ENV=development webpack", "build": "webpack --env.dev",
"build:prod": "cross-env NODE_ENV=production webpack -p", "build:prod": "webpack --env.prod -p",
"lint": "eslint ." "lint": "eslint ."
} }
} }

View File

@ -1,4 +1,4 @@
import Controller from '../src/js/controller' import Controller from './controller'
describe('controller', () => { describe('controller', () => {
var subject, model, view var subject, model, view

View File

@ -1,9 +0,0 @@
{
"globals": {
"jasmine": false,
"describe": false,
"it": false,
"beforeEach": false,
"expect": false,
}
}

View File

@ -1,18 +1,19 @@
const {resolve} = require('path') const {resolve} = require('path')
const isProd = process.env.NODE_ENV === 'production' module.exports = env => {
module.exports = { return {
entry: './js/app.js', entry: './js/app.js',
output: { output: {
filename: 'bundle.js', filename: 'bundle.js',
path: resolve(__dirname, 'dist'), path: resolve(__dirname, 'dist'),
pathinfo: true, pathinfo: true,
}, },
context: resolve(__dirname, 'src'), context: resolve(__dirname, 'src'),
devtool: isProd ? 'source-map' : 'eval', devtool: env.prod ? 'source-map' : 'eval',
module: { module: {
loaders: [ loaders: [
{test: /\.js$/, loader: 'babel!eslint', exclude: /node_modules/}, {test: /\.js$/, loader: 'babel!eslint', exclude: /node_modules/},
{test: /\.css$/, loader: 'style!css'}, {test: /\.css$/, loader: 'style!css'},
], ],
}, },
}
} }