Skip to content

Minor refactoring of build scripts #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion template/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spinner.start()

rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
if (err) throw err
webpack(webpackConfig, function (err, stats) {
webpack(webpackConfig, (err, stats) => {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
Expand Down
5 changes: 5 additions & 0 deletions template/build/check-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const chalk = require('chalk')
const semver = require('semver')
const packageConfig = require('../package.json')
const shell = require('shelljs')

function exec (cmd) {
return require('child_process').execSync(cmd).toString().trim()
}
Expand All @@ -25,8 +26,10 @@ if (shell.which('npm')) {

module.exports = function () {
const warnings = []

for (let i = 0; i < versionRequirements.length; i++) {
const mod = versionRequirements[i]

if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
warnings.push(mod.name + ': ' +
chalk.red(mod.currentVersion) + ' should be ' +
Expand All @@ -39,10 +42,12 @@ module.exports = function () {
console.log('')
console.log(chalk.yellow('To use this template, you must update following to modules:'))
console.log()

for (let i = 0; i < warnings.length; i++) {
const warning = warnings[i]
console.log(' ' + warning)
}

console.log()
process.exit(1)
}
Expand Down
19 changes: 11 additions & 8 deletions template/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const pkg = require('../package.json')
const packageConfig = require('../package.json')

exports.assetsPath = function (_path) {
const assetsSubDirectory = process.env.NODE_ENV === 'production'
? config.build.assetsSubDirectory
: config.dev.assetsSubDirectory

return path.posix.join(assetsSubDirectory, _path)
}

Expand All @@ -21,7 +22,7 @@ exports.cssLoaders = function (options) {
}
}

var postcssLoader = {
const postcssLoader = {
loader: 'postcss-loader',
options: {
sourceMap: options.sourceMap
Expand All @@ -31,6 +32,7 @@ exports.cssLoaders = function (options) {
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]

if (loader) {
loaders.push({
loader: loader + '-loader',
Expand Down Expand Up @@ -68,28 +70,29 @@ exports.cssLoaders = function (options) {
exports.styleLoaders = function (options) {
const output = []
const loaders = exports.cssLoaders(options)

for (const extension in loaders) {
const loader = loaders[extension]
output.push({
test: new RegExp('\\.' + extension + '$'),
use: loader
})
}

return output
}

exports.createNotifierCallback = function () {
exports.createNotifierCallback = () => {
const notifier = require('node-notifier')

return (severity, errors) => {
if (severity !== 'error') {
return
}
const error = errors[0]
if (severity !== 'error') return

const error = errors[0]
const filename = error.file && error.file.split('!').pop()

notifier.notify({
title: pkg.name,
title: packageConfig.name,
message: severity + ': ' + error.name,
subtitle: filename || '',
icon: path.join(__dirname, 'logo.png')
Expand Down
3 changes: 1 addition & 2 deletions template/build/vue-loader.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ const sourceMapEnabled = isProduction
? config.build.productionSourceMap
: config.dev.cssSourceMap


module.exports = {
loaders: utils.cssLoaders({
sourceMap: sourceMapEnabled,
extract: isProduction
}),
cssSourceMap: sourceMapEnabled,
cacheBusting: config.dev.cacheBusting,
cacheBusting: config.dev.cacheBusting,
transformToRequire: {
video: 'src',
source: 'src',
Expand Down
22 changes: 12 additions & 10 deletions template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ function resolve (dir) {
return path.join(__dirname, '..', dir)
}

const lintingRule = {
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: require('eslint-friendly-formatter'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this want not a bad idea in hindsight - this will break if the user has decided against using eslint during the project init. Will fix it.

emitWarning: !config.dev.showEslintErrorsInOverlay
}
}

module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
Expand All @@ -32,16 +43,7 @@ module.exports = {
module: {
rules: [
{{#lint}}
...(config.dev.useEslint? [{
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: require('eslint-friendly-formatter'),
emitWarning: !config.dev.showEslintErrorsInOverlay
}
}] : []),
...(config.dev.useEslint ? [lintingRule] : []),
{{/lint}}
{
test: /\.vue$/,
Expand Down
7 changes: 3 additions & 4 deletions template/build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ const devWebpackConfig = merge(baseWebpackConfig, {
host: process.env.HOST || config.dev.host,
port: process.env.PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay ? {
warnings: false,
errors: true,
} : false,
overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
Expand Down
6 changes: 3 additions & 3 deletions template/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const webpackConfig = merge(baseWebpackConfig, {
// duplicated CSS from different components can be deduped.
new OptimizeCSSPlugin({
cssProcessorOptions: config.build.productionSourceMap
? { safe: true, map: { inline: false } }
: { safe: true }
? { safe: true, map: { inline: false } }
: { safe: true }
}),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
Expand Down Expand Up @@ -82,7 +82,7 @@ const webpackConfig = merge(baseWebpackConfig, {
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
minChunks (module) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
Expand Down