Skip to content

Commit

Permalink
eslint: build and config
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 1, 2016
1 parent 22c9b11 commit 2339705
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 44 deletions.
4 changes: 3 additions & 1 deletion build/dev-client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

/* eslint-disable */
require('eventsource-polyfill')
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')

hotClient.subscribe((event) => {
hotClient.subscribe(event => {
if (event.action === 'reload') {
window.location.reload()
}
Expand Down
42 changes: 22 additions & 20 deletions build/dev-server.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var opn = require('opn')
var config = require('../config')
var proxyMiddleware = require('http-proxy-middleware')
var webpackConfig = process.env.NODE_ENV === 'testing'
'use strict'

const path = require('path')
const express = require('express')
const webpack = require('webpack')
const opn = require('opn')
const config = require('../config')
const proxyMiddleware = require('http-proxy-middleware')
const webpackConfig = process.env.NODE_ENV === 'testing'
? require('./webpack.prod.conf')
: require('./webpack.dev.conf')

// default port where dev server listens for incoming traffic
var port = process.env.PORT || config.dev.port
const port = process.env.PORT || config.dev.port
// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
var proxyTable = config.dev.proxyTable
const proxyTable = config.dev.proxyTable

var app = express()
var compiler = webpack(webpackConfig)
const app = express()
const compiler = webpack(webpackConfig)

var devMiddleware = require('webpack-dev-middleware')(compiler, {
const devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
}
})

var hotMiddleware = require('webpack-hot-middleware')(compiler)
const hotMiddleware = require('webpack-hot-middleware')(compiler)
// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
compiler.plugin('compilation', compilation => {
compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => {
hotMiddleware.publish({ action: 'reload' })
cb()
})
})

// proxy api requests
Object.keys(proxyTable).forEach(function (context) {
var options = proxyTable[context]
Object.keys(proxyTable).forEach(context => {
let options = proxyTable[context]
if (typeof options === 'string') {
options = { target: options }
}
Expand All @@ -54,15 +56,15 @@ app.use(devMiddleware)
app.use(hotMiddleware)

// serve pure static assets
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./assets'))

module.exports = app.listen(port, function (err) {
module.exports = app.listen(port, err => {
if (err) {
console.log(err)
return
}
var uri = 'http://localhost:' + port
const uri = 'http://localhost:' + port
console.log('Listening at ' + uri + '\n')
opn(uri)
})
28 changes: 15 additions & 13 deletions build/utils.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
var path = require('path')
var config = require('../config')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
'use strict'

exports.assetsPath = function (_path) {
var assetsSubDirectory = process.env.NODE_ENV === 'production'
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

exports.assetsPath = _path => {
const assetsSubDirectory = process.env.NODE_ENV === 'production'
? config.build.assetsSubDirectory
: config.dev.assetsSubDirectory
return path.posix.join(assetsSubDirectory, _path)
}

exports.cssLoaders = function (options) {
exports.cssLoaders = options => {
options = options || {}
// generate loader string to be used with extract text plugin
function generateLoaders (loaders) {
var sourceLoader = loaders.map(function (loader) {
var extraParamChar
const sourceLoader = loaders.map(function (loader) {
let extraParamChar
if (/\?/.test(loader)) {
loader = loader.replace(/\?/, '-loader?')
extraParamChar = '&'
Expand Down Expand Up @@ -48,11 +50,11 @@ exports.cssLoaders = function (options) {
}

// Generate loaders for standalone style files (outside of .vue)
exports.styleLoaders = function (options) {
var output = []
var loaders = exports.cssLoaders(options)
for (var extension in loaders) {
var loader = loaders[extension]
exports.styleLoaders = options => {
const output = []
const loaders = exports.cssLoaders(options)
for (const extension in loaders) {
const loader = loaders[extension]
output.push({
test: new RegExp('\\.' + extension + '$'),
loader: loader
Expand Down
8 changes: 4 additions & 4 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ module.exports = {
loaders: [
{
test: /\.vue$/,
loader: ['eslint-loader'],
loader: 'eslint-loader',
include: projectRoot,
exclude: /node_modules/,
enforce: 'pre'
},
{
test: /\.js$/,
loader: ['eslint-loader'],
loader: 'eslint-loader',
include: projectRoot,
exclude: /node_modules/,
enforce: 'pre'
},
{
test: /\.vue$/,
loader: ['vue-loader']
loader: 'vue-loader'
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.js$/,
loader: ['babel-loader'],
loader: 'babel-loader',
include: projectRoot,
// /node_modules\/(?!vue-bulma-.*)/
exclude: [new RegExp(`node_modules\\${path.sep}(?!vue-bulma-.*)`)]
Expand Down
4 changes: 3 additions & 1 deletion build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const webpack = require('webpack')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
Expand All @@ -6,7 +8,7 @@ const config = require('../config')
const utils = require('./utils')

// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
Object.keys(baseWebpackConfig.entry).forEach(name => {
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})

Expand Down
1 change: 1 addition & 0 deletions build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const webpackConfig = merge(baseWebpackConfig, {
minimize: true
}),
new webpack.optimize.UglifyJsPlugin({
'screw-ie8': true,
sourceMap: true,
compress: {
warnings: false
Expand Down
6 changes: 4 additions & 2 deletions config/dev.env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var merge = require('webpack-merge')
var prodEnv = require('./prod.env')
'use strict'

const merge = require('webpack-merge')
const prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
NODE_ENV: '"development"'
Expand Down
4 changes: 3 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
const path = require('path')

module.exports = {
build: {
Expand Down
2 changes: 2 additions & 0 deletions config/prod.env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

module.exports = {
NODE_ENV: '"production"'
}
6 changes: 4 additions & 2 deletions config/test.env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var merge = require('webpack-merge')
var devEnv = require('./dev.env')
'use strict'

const merge = require('webpack-merge')
const devEnv = require('./dev.env')

module.exports = merge(devEnv, {
NODE_ENV: '"testing"'
Expand Down

0 comments on commit 2339705

Please sign in to comment.