UNPKG

wox-cli

Version:

scaffold for create component, toolkit and so on

83 lines (74 loc) 2.44 kB
'use strict'; const webpack = require('webpack'); const merge = require('webpack-merge'); const path = require('path'); const baseWebpackConfig = require('./webpack.base.conf'); 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: 'inline-source-map', 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: true, openPage: 'index.html', 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(), ] }); 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); } }); });