Switch to webpack 2.

This commit is contained in:
Roger Braun 2017-02-10 14:52:19 +01:00
parent 038798f3f4
commit 18af6fa147
18 changed files with 1652 additions and 2122 deletions

View File

@ -1,5 +1,13 @@
{ {
"presets": ["es2015", "stage-2"], "presets": [
"plugins": ["transform-runtime"], ["es2015", { "modules": false }],
"comments": false "stage-2"
],
"plugins": ["transform-runtime", "lodash"],
"comments": false,
"env": {
"test": {
"plugins": [ "istanbul" ]
}
}
} }

View File

@ -1,9 +1,14 @@
// http://eslint.org/docs/user-guide/configuring
module.exports = { module.exports = {
root: true, root: true,
parser: 'babel-eslint', parser: 'babel-eslint',
parserOptions: { parserOptions: {
sourceType: 'module' sourceType: 'module'
}, },
env: {
browser: true,
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard', extends: 'standard',
// required to lint *.vue files // required to lint *.vue files

1
.node-version Normal file
View File

@ -0,0 +1 @@
7.2.1

View File

@ -1,27 +1,25 @@
// https://github.com/shelljs/shelljs // https://github.com/shelljs/shelljs
require('./check-versions')() require('./check-versions')()
require('shelljs/global')
env.NODE_ENV = 'production'
var path = require('path') process.env.NODE_ENV = 'production'
var config = require('../config')
var ora = require('ora') var ora = require('ora')
var path = require('path')
var chalk = require('chalk')
var shell = require('shelljs')
var webpack = require('webpack') var webpack = require('webpack')
var config = require('../config')
var webpackConfig = require('./webpack.prod.conf') var webpackConfig = require('./webpack.prod.conf')
console.log(
' Tip:\n' +
' Built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
)
var spinner = ora('building for production...') var spinner = ora('building for production...')
spinner.start() spinner.start()
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory) var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
rm('-rf', assetsPath) shell.rm('-rf', assetsPath)
mkdir('-p', assetsPath) shell.mkdir('-p', assetsPath)
cp('-R', 'static/*', assetsPath) shell.config.silent = true
shell.cp('-R', 'static/*', assetsPath)
shell.config.silent = false
webpack(webpackConfig, function (err, stats) { webpack(webpackConfig, function (err, stats) {
spinner.stop() spinner.stop()
@ -32,5 +30,11 @@ webpack(webpackConfig, function (err, stats) {
children: false, children: false,
chunks: false, chunks: false,
chunkModules: false chunkModules: false
}) + '\n') }) + '\n\n')
console.log(chalk.cyan(' Build complete.\n'))
console.log(chalk.yellow(
' Tip: built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
))
}) })

View File

@ -1,9 +1,9 @@
var semver = require('semver')
var chalk = require('chalk') var chalk = require('chalk')
var semver = require('semver')
var packageConfig = require('../package.json') var packageConfig = require('../package.json')
var exec = function (cmd) {
return require('child_process') function exec (cmd) {
.execSync(cmd).toString().trim() return require('child_process').execSync(cmd).toString().trim()
} }
var versionRequirements = [ var versionRequirements = [

View File

@ -1,10 +1,14 @@
require('./check-versions')() require('./check-versions')()
var config = require('../config') var config = require('../config')
if (!process.env.NODE_ENV) process.env.NODE_ENV = config.dev.env if (!process.env.NODE_ENV) {
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
}
var opn = require('opn')
var path = require('path') var path = require('path')
var express = require('express') var express = require('express')
var webpack = require('webpack') var webpack = require('webpack')
var opn = require('opn')
var proxyMiddleware = require('http-proxy-middleware') var proxyMiddleware = require('http-proxy-middleware')
var webpackConfig = process.env.NODE_ENV === 'testing' var webpackConfig = process.env.NODE_ENV === 'testing'
? require('./webpack.prod.conf') ? require('./webpack.prod.conf')
@ -12,6 +16,8 @@ var webpackConfig = process.env.NODE_ENV === 'testing'
// default port where dev server listens for incoming traffic // default port where dev server listens for incoming traffic
var port = process.env.PORT || config.dev.port var port = process.env.PORT || config.dev.port
// automatically open browser, if not set will be false
var autoOpenBrowser = !!config.dev.autoOpenBrowser
// Define HTTP proxies to your custom API backend // Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware // https://github.com/chimurai/http-proxy-middleware
var proxyTable = config.dev.proxyTable var proxyTable = config.dev.proxyTable
@ -21,13 +27,12 @@ var compiler = webpack(webpackConfig)
var devMiddleware = require('webpack-dev-middleware')(compiler, { var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath, publicPath: webpackConfig.output.publicPath,
stats: { quiet: true
colors: true,
chunks: false
}
}) })
var hotMiddleware = require('webpack-hot-middleware')(compiler) var hotMiddleware = require('webpack-hot-middleware')(compiler, {
log: () => {}
})
// force page reload when html-webpack-plugin template changes // force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) { compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
@ -42,7 +47,7 @@ Object.keys(proxyTable).forEach(function (context) {
if (typeof options === 'string') { if (typeof options === 'string') {
options = { target: options } options = { target: options }
} }
app.use(proxyMiddleware(context, options)) app.use(proxyMiddleware(options.filter || context, options))
}) })
// handle fallback for HTML5 history API // handle fallback for HTML5 history API
@ -59,12 +64,20 @@ app.use(hotMiddleware)
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static')) app.use(staticPath, express.static('./static'))
var uri = 'http://localhost:' + port
devMiddleware.waitUntilValid(function () {
console.log('> Listening at ' + uri + '\n')
})
module.exports = app.listen(port, function (err) { module.exports = app.listen(port, function (err) {
if (err) { if (err) {
console.log(err) console.log(err)
return return
} }
var uri = 'http://localhost:' + port
console.log('Listening at ' + uri + '\n') // when env is testing, don't need open it
// opn(uri) if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}
}) })

View File

@ -28,13 +28,16 @@ exports.cssLoaders = function (options) {
// Extract CSS when that option is specified // Extract CSS when that option is specified
// (which is the case during production build) // (which is the case during production build)
if (options.extract) { if (options.extract) {
return ExtractTextPlugin.extract('vue-style-loader', sourceLoader) return ExtractTextPlugin.extract({
use: sourceLoader,
fallback: 'vue-style-loader'
})
} else { } else {
return ['vue-style-loader', sourceLoader].join('!') return ['vue-style-loader', sourceLoader].join('!')
} }
} }
// http://vuejs.github.io/vue-loader/configurations/extract-css.html // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
return { return {
css: generateLoaders(['css']), css: generateLoaders(['css']),
postcss: generateLoaders(['css']), postcss: generateLoaders(['css']),

17
build/vue-loader.conf.js Normal file
View File

@ -0,0 +1,17 @@
var utils = require('./utils')
var config = require('../config')
var isProduction = process.env.NODE_ENV === 'production'
module.exports = {
loaders: utils.cssLoaders({
sourceMap: isProduction
? config.build.productionSourceMap
: config.dev.cssSourceMap,
extract: isProduction
}),
postcss: [
require('autoprefixer')({
browsers: ['last 2 versions']
})
]
}

View File

@ -1,70 +1,60 @@
var path = require('path') var path = require('path')
var config = require('../config')
var utils = require('./utils') var utils = require('./utils')
var projectRoot = path.resolve(__dirname, '../') var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf')
var env = process.env.NODE_ENV function resolve (dir) {
// check env & config/index.js to decide weither to enable CSS Sourcemaps for the return path.join(__dirname, '..', dir)
// various preprocessor loaders added to vue-loader at the end of this file }
var cssSourceMapDev = (env === 'development' && config.dev.cssSourceMap)
var cssSourceMapProd = (env === 'production' && config.build.productionSourceMap)
var useCssSourceMap = cssSourceMapDev || cssSourceMapProd
module.exports = { module.exports = {
entry: { entry: {
app: './src/main.js' app: ['babel-polyfill', './src/main.js']
}, },
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath, filename: '[name].js',
filename: '[name].js' publicPath: process.env.NODE_EN === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
}, },
resolve: { resolve: {
extensions: ['', '.js', '.vue'], extensions: ['.js', '.vue', '.json'],
fallback: [path.join(__dirname, '../node_modules')], modules: [
resolve('src'),
resolve('node_modules')
],
alias: { alias: {
'vue$': 'vue/dist/vue', 'vue$': 'vue/dist/vue.common.js',
'src': path.resolve(__dirname, '../src'), 'src': resolve('src'),
'assets': path.resolve(__dirname, '../src/assets'), 'assets': resolve('src/assets'),
'components': path.resolve(__dirname, '../src/components') 'components': resolve('src/components')
} }
}, },
resolveLoader: {
fallback: [path.join(__dirname, '../node_modules')]
},
module: { module: {
preLoaders: [ rules: [
{ {
test: /\.vue$/, test: /\.(js|vue)$/,
loader: 'eslint', loader: 'eslint-loader',
include: projectRoot, enforce: "pre",
exclude: /node_modules/ include: [resolve('src'), resolve('test')],
}, options: {
{ formatter: require('eslint-friendly-formatter')
test: /\.js$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
} }
], },
loaders: [
{ {
test: /\.vue$/, test: /\.vue$/,
loader: 'vue' loader: 'vue-loader',
options: vueLoaderConfig
}, },
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel', loader: 'babel-loader',
include: projectRoot, include: [resolve('src'), resolve('test'), resolve('node_modules/tributejs')]
exclude: /node_modules\/(?!tributejs)/
},
{
test: /\.json$/,
loader: 'json'
}, },
{ {
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url', loader: 'url-loader',
query: { query: {
limit: 10000, limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]') name: utils.assetsPath('img/[name].[hash:7].[ext]')
@ -72,23 +62,12 @@ module.exports = {
}, },
{ {
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url', loader: 'url-loader',
query: { query: {
limit: 10000, limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]') name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
} }
} }
] ]
},
eslint: {
formatter: require('eslint-friendly-formatter')
},
vue: {
loaders: utils.cssLoaders({ sourceMap: useCssSourceMap }),
postcss: [
require('autoprefixer')({
browsers: ['last 2 versions']
})
]
} }
} }

View File

@ -1,9 +1,10 @@
var config = require('../config')
var webpack = require('webpack')
var merge = require('webpack-merge')
var utils = require('./utils') var utils = require('./utils')
var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf') var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin') var HtmlWebpackPlugin = require('html-webpack-plugin')
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
// add hot-reload related code to entry chunks // add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) { Object.keys(baseWebpackConfig.entry).forEach(function (name) {
@ -12,23 +13,23 @@ Object.keys(baseWebpackConfig.entry).forEach(function (name) {
module.exports = merge(baseWebpackConfig, { module.exports = merge(baseWebpackConfig, {
module: { module: {
loaders: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
}, },
// eval-source-map is faster for development // cheap-module-eval-source-map is faster for development
devtool: '#eval-source-map', devtool: '#cheap-module-eval-source-map',
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': config.dev.env 'process.env': config.dev.env
}), }),
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(), new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(), new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin // https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
filename: 'index.html', filename: 'index.html',
template: 'index.html', template: 'index.html',
inject: true inject: true
}) }),
new FriendlyErrorsPlugin()
] ]
}) })

View File

@ -1,18 +1,21 @@
var path = require('path') var path = require('path')
var config = require('../config')
var utils = require('./utils') var utils = require('./utils')
var webpack = require('webpack') var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge') var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf') var baseWebpackConfig = require('./webpack.base.conf')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin') var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var env = process.env.NODE_ENV === 'testing' var env = process.env.NODE_ENV === 'testing'
? require('../config/test.env') ? require('../config/test.env')
: config.build.env : config.build.env
var webpackConfig = merge(baseWebpackConfig, { var webpackConfig = merge(baseWebpackConfig, {
module: { module: {
loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true }) rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true
})
}, },
devtool: config.build.productionSourceMap ? '#source-map' : false, devtool: config.build.productionSourceMap ? '#source-map' : false,
output: { output: {
@ -20,14 +23,8 @@ var webpackConfig = merge(baseWebpackConfig, {
filename: utils.assetsPath('js/[name].[chunkhash].js'), filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
}, },
vue: {
loaders: utils.cssLoaders({
sourceMap: config.build.productionSourceMap,
extract: true
})
},
plugins: [ plugins: [
// http://vuejs.github.io/vue-loader/workflow/production.html // http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': env 'process.env': env
}), }),
@ -36,9 +33,10 @@ var webpackConfig = merge(baseWebpackConfig, {
warnings: false warnings: false
} }
}), }),
new webpack.optimize.OccurenceOrderPlugin(),
// extract css into its own file // extract css into its own file
new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')), new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css')
}),
// generate dist index.html with correct asset hash for caching. // generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html // you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin // see https://github.com/ampedandwired/html-webpack-plugin
@ -99,4 +97,9 @@ if (config.build.productionGzip) {
) )
} }
if (config.build.bundleAnalyzerReport) {
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
module.exports = webpackConfig module.exports = webpackConfig

View File

@ -0,0 +1,24 @@
// This is the webpack config used for unit tests.
var utils = require('./utils')
var webpack = require('webpack')
var merge = require('webpack-merge')
var baseConfig = require('./webpack.base.conf')
var webpackConfig = merge(baseConfig, {
// use inline sourcemap for karma-sourcemap-loader
module: {
rules: utils.styleLoaders()
},
devtool: '#inline-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/test.env')
})
]
})
// no need for app entry during tests
delete webpackConfig.entry
module.exports = webpackConfig

View File

@ -14,7 +14,12 @@ module.exports = {
// Before setting to `true`, make sure to: // Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin // npm install --save-dev compression-webpack-plugin
productionGzip: false, productionGzip: false,
productionGzipExtensions: ['js', 'css'] productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}, },
dev: { dev: {
env: require('./dev.env'), env: require('./dev.env'),

View File

@ -7,84 +7,82 @@
"scripts": { "scripts": {
"dev": "node build/dev-server.js", "dev": "node build/dev-server.js",
"build": "node build/build.js", "build": "node build/build.js",
"unit": "karma start test/unit/karma.conf.js --single-run", "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"e2e": "node test/e2e/runner.js", "test": "npm run unit",
"test": "npm run unit && npm run e2e", "lint": "eslint --ext .js,.vue src test/unit/specs"
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
}, },
"dependencies": { "dependencies": {
"babel-plugin-add-module-exports": "^0.2.1", "babel-plugin-add-module-exports": "^0.2.1",
"diff": "^3.0.1", "babel-plugin-lodash": "^3.2.11",
"karma-mocha-reporter": "^2.2.1", "babel-polyfill": "^6.22.0",
"lodash": "^4.17.4",
"lodash-es": "^4.17.4",
"node-sass": "^3.10.1", "node-sass": "^3.10.1",
"sanitize-html": "^1.13.0", "sanitize-html": "^1.13.0",
"sass-loader": "^4.0.2", "sass-loader": "^4.0.2",
"tributejs": "^2.1.0", "tributejs": "^2.1.0",
"vue": "^2.0.1", "vue": "^2.1.10",
"vue-router": "^2.0.1", "vue-router": "^2.2.0",
"vue-timeago": "^3.1.2", "vue-timeago": "^3.1.2",
"vuex": "^2.0.0" "vuex": "^2.0.0"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "^6.4.0", "autoprefixer": "^6.7.2",
"babel-core": "^6.0.0", "babel-core": "^6.22.1",
"babel-eslint": "^7.0.0", "babel-eslint": "^7.1.1",
"babel-loader": "^6.0.0", "babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.0.0", "babel-plugin-istanbul": "^3.1.2",
"babel-preset-es2015": "^6.0.0", "babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-stage-2": "^6.0.0", "babel-preset-es2015": "^6.22.0",
"babel-register": "^6.0.0", "babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chai": "^3.5.0", "chai": "^3.5.0",
"chalk": "^1.1.3", "chalk": "^1.1.3",
"chromedriver": "^2.21.2", "connect-history-api-fallback": "^1.3.0",
"connect-history-api-fallback": "^1.1.0", "cross-env": "^3.1.4",
"cross-spawn": "^4.0.2", "css-loader": "^0.26.1",
"css-loader": "^0.25.0", "eslint": "^3.14.1",
"eslint": "^3.7.1", "eslint-config-standard": "^6.2.1",
"eslint-config-standard": "^6.1.0", "eslint-friendly-formatter": "^2.0.7",
"eslint-friendly-formatter": "^2.0.5", "eslint-loader": "^1.6.1",
"eslint-loader": "^1.5.0", "eslint-plugin-html": "^2.0.0",
"eslint-plugin-html": "^1.5.5", "eslint-plugin-promise": "^3.4.0",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.1", "eslint-plugin-standard": "^2.0.1",
"eventsource-polyfill": "^0.9.6", "eventsource-polyfill": "^0.9.6",
"express": "^4.13.3", "express": "^4.14.1",
"extract-text-webpack-plugin": "^1.0.1", "extract-text-webpack-plugin": "^2.0.0-rc.2",
"file-loader": "^0.9.0", "file-loader": "^0.10.0",
"function-bind": "^1.0.2", "friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.8.1", "function-bind": "^1.1.0",
"http-proxy-middleware": "^0.17.2", "html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"inject-loader": "^2.0.1", "inject-loader": "^2.0.1",
"isparta-loader": "^2.0.0", "karma": "^1.4.1",
"json-loader": "^0.5.4",
"karma": "^1.3.0",
"karma-coverage": "^1.1.1", "karma-coverage": "^1.1.1",
"karma-mocha": "^1.2.0", "karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.0", "karma-phantomjs-launcher": "^1.0.2",
"karma-sinon-chai": "^1.2.0", "karma-sinon-chai": "^1.2.4",
"karma-sourcemap-loader": "^0.3.7", "karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.26", "karma-spec-reporter": "0.0.26",
"karma-webpack": "^1.7.0", "karma-webpack": "^2.0.2",
"lodash": "^4.16.4", "lolex": "^1.5.2",
"lolex": "^1.4.0", "mocha": "^3.2.0",
"mocha": "^3.1.0",
"nightwatch": "^0.9.8",
"opn": "^4.0.2", "opn": "^4.0.2",
"ora": "^0.3.0", "ora": "^1.1.0",
"phantomjs-prebuilt": "^2.1.3", "phantomjs-prebuilt": "^2.1.14",
"raw-loader": "^0.5.1",
"selenium-server": "2.53.1",
"semver": "^5.3.0", "semver": "^5.3.0",
"shelljs": "^0.7.4", "shelljs": "^0.7.6",
"sinon": "^1.17.3", "sinon": "^1.17.7",
"sinon-chai": "^2.8.0", "sinon-chai": "^2.8.0",
"url-loader": "^0.5.7", "url-loader": "^0.5.7",
"vue-loader": "^9.4.0", "vue-loader": "^10.3.0",
"vue-style-loader": "^1.0.0", "vue-style-loader": "^2.0.0",
"webpack": "^1.13.2", "vue-template-compiler": "^2.1.10",
"webpack-dev-middleware": "^1.8.3", "webpack": "^2.2.1",
"webpack-hot-middleware": "^2.12.2", "webpack-bundle-analyzer": "^2.2.1",
"webpack-merge": "^0.14.1" "webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.16.1",
"webpack-merge": "^2.6.1"
}, },
"engines": { "engines": {
"node": ">= 4.0.0", "node": ">= 4.0.0",

View File

@ -84,7 +84,9 @@ export const statusType = (status) => {
} }
export const findMaxId = (...args) => { export const findMaxId = (...args) => {
return (maxBy(flatten(args), 'id') || {}).id const flattened = flatten(args)
return (maxBy(flattened, 'id') || {}).id
} }
const mergeOrAdd = (arr, item) => { const mergeOrAdd = (arr, item) => {

View File

@ -9,5 +9,5 @@ testsContext.keys().forEach(testsContext)
// require all src files except main.js for coverage. // require all src files except main.js for coverage.
// you can also change this to match only the subset of files that // you can also change this to match only the subset of files that
// you want coverage for. // you want coverage for.
const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) const srcContext = require.context('src', true, /^\.\/(?!main(\.js)?$)/)
srcContext.keys().forEach(srcContext) srcContext.keys().forEach(srcContext)

View File

@ -3,49 +3,7 @@
// we are also using it with karma-webpack // we are also using it with karma-webpack
// https://github.com/webpack/karma-webpack // https://github.com/webpack/karma-webpack
var path = require('path') var webpackConfig = require('../../build/webpack.test.conf')
var merge = require('webpack-merge')
var baseConfig = require('../../build/webpack.base.conf')
var utils = require('../../build/utils')
var webpack = require('webpack')
var projectRoot = path.resolve(__dirname, '../../')
var webpackConfig = merge(baseConfig, {
// use inline sourcemap for karma-sourcemap-loader
module: {
loaders: utils.styleLoaders()
},
devtool: '#inline-source-map',
// vue: {
// loaders: {
// js: 'isparta'
// }
// },
plugins: [
new webpack.DefinePlugin({
'process.env': require('../../config/test.env')
})
]
})
// no need for app entry during tests
delete webpackConfig.entry
// make sure isparta loader is applied before eslint
// webpackConfig.module.preLoaders = webpackConfig.module.preLoaders || []
// webpackConfig.module.preLoaders.unshift({
// test: /\.js$/,
// loader: 'isparta',
// include: path.resolve(projectRoot, 'src')
// })
// // only apply babel for test files when using isparta
// webpackConfig.module.loaders.some(function (loader, i) {
// if (loader.loader === 'babel') {
// loader.include = path.resolve(projectRoot, 'test/unit')
// return true
// }
// })
module.exports = function (config) { module.exports = function (config) {
config.set({ config.set({
@ -55,7 +13,7 @@ module.exports = function (config) {
// 2. add it to the `browsers` array below. // 2. add it to the `browsers` array below.
browsers: ['PhantomJS'], browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon-chai'], frameworks: ['mocha', 'sinon-chai'],
reporters: ['mocha'], reporters: ['spec', 'coverage'],
files: ['./index.js'], files: ['./index.js'],
preprocessors: { preprocessors: {
'./index.js': ['webpack', 'sourcemap'] './index.js': ['webpack', 'sourcemap']
@ -64,9 +22,6 @@ module.exports = function (config) {
webpackMiddleware: { webpackMiddleware: {
noInfo: true noInfo: true
}, },
mochaReporter: {
showDiff: true
},
coverageReporter: { coverageReporter: {
dir: './coverage', dir: './coverage',
reporters: [ reporters: [

3324
yarn.lock

File diff suppressed because it is too large Load Diff