cygnal/build/webpack.dev.conf.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-06-25 18:29:57 +02:00
'use strict'
const path = require('path')
const portfinder = require('portfinder')
2018-06-25 18:29:57 +02:00
const webpack = require('webpack')
const merge = require('webpack-merge')
2018-06-25 18:29:57 +02:00
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const baseWebpackConfig = require('./webpack.base.conf')
const config = require('../config')
const env = require('../config/dev.env');
2018-06-25 18:29:57 +02:00
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT)
const devWebpackConfig = merge(baseWebpackConfig, {
mode: 'development',
2018-07-11 02:43:14 +02:00
// cheap-module-eval-source-map is faster for development
devtool: 'cheap-module-eval-source-map',
2018-06-25 18:29:57 +02:00
2018-07-11 02:43:14 +02:00
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.build.assetsPublicPath, 'index.html') },
2018-07-11 02:43:14 +02:00
],
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: { warnings: false, errors: true },
publicPath: config.build.assetsPublicPath,
2018-07-11 02:43:14 +02:00
quiet: true, // necessary for FriendlyErrorsPlugin
2018-06-25 18:29:57 +02:00
},
2018-07-11 02:43:14 +02:00
plugins: [
new webpack.DefinePlugin({
'process.env': env,
2018-07-11 02:43:14 +02:00
}),
new webpack.HotModuleReplacementPlugin(),
]
2018-06-25 18:29:57 +02:00
})
module.exports = new Promise((resolve, reject) => {
2018-07-11 02:43:14 +02:00
portfinder.basePort = process.env.PORT || config.dev.port
portfinder.getPort((err, port) => {
if (err) {
reject(err)
} else {
// add port to devServer config
devWebpackConfig.devServer.port = port
2018-06-25 18:29:57 +02:00
2018-07-11 02:43:14 +02:00
// Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
}))
2018-06-25 18:29:57 +02:00
2018-07-11 02:43:14 +02:00
resolve(devWebpackConfig)
}
})
2018-06-25 18:29:57 +02:00
})