wox-cli
Version:
scaffold for create component, toolkit and so on
92 lines (82 loc) • 2.78 kB
JavaScript
'use strict';
const webpack = require('webpack');
const merge = require('webpack-merge');
const path = require('path');
const baseWebpackConfig = require('./webpack.base.conf');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const portfinder = require('portfinder');
const notifier = require('node-notifier');
const HOST = process.env.HOST;
const PORT = process.env.PORT && Number(process.env.PORT);
const devWebpackConfig = merge(baseWebpackConfig, {
devtool: 'cheap-module-eval-source-map',
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join('/', 'index.html') },
],
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || '0.0.0.0',
port: PORT || '8080',
open: false,
overlay: { warnings: false, errors: true },
publicPath: '/',
proxy: {},
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: false,
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: '"development"' }
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
})
]
});
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || '8080';
portfinder.getPort((err, port) => {
if (err) {
reject(err);
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port;
// add port to devServer config
devWebpackConfig.devServer.port = port;
// Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
onErrors: (severity, errors) => {
if (severity !== 'error') return
const error = errors[0]
const filename = error.file && error.file.split('!').pop()
notifier.notify({
title: 'vue',
message: severity + ': ' + error.name,
subtitle: filename || '',
icon: path.join(__dirname, './logo.png')
})
}
}));
resolve(devWebpackConfig);
}
});
});