Path: blob/develop/web/build/webpack.dev.conf.js
387 views
'use strict'1const utils = require('./utils')2const webpack = require('webpack')3const config = require('../config')4const merge = require('webpack-merge')5const path = require('path')6const baseWebpackConfig = require('./webpack.base.conf')7const CopyWebpackPlugin = require('copy-webpack-plugin')8const HtmlWebpackPlugin = require('html-webpack-plugin')9const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')10const portfinder = require('portfinder')1112const HOST = process.env.HOST13const PORT = process.env.PORT && Number(process.env.PORT)1415const devWebpackConfig = merge(baseWebpackConfig, {16module: {17rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })18},19// cheap-module-eval-source-map is faster for development20devtool: config.dev.devtool,2122// these devServer options should be customized in /config/index.js23devServer: {24clientLogLevel: 'warning',25historyApiFallback: {26rewrites: [27{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },28],29},30hot: true,31contentBase: false, // since we use CopyWebpackPlugin.32compress: true,33host: HOST || config.dev.host,34port: PORT || config.dev.port,35open: config.dev.autoOpenBrowser,36overlay: config.dev.errorOverlay37? { warnings: false, errors: true }38: false,39publicPath: config.dev.assetsPublicPath,40proxy: config.dev.proxyTable,41quiet: true, // necessary for FriendlyErrorsPlugin42watchOptions: {43poll: config.dev.poll,44}45},46plugins: [47new webpack.DefinePlugin({48'process.env': require('../config/dev.env')49}),50new webpack.HotModuleReplacementPlugin(),51new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.52new webpack.NoEmitOnErrorsPlugin(),53// https://github.com/ampedandwired/html-webpack-plugin54new HtmlWebpackPlugin({55filename: 'index.html',56template: 'index.html',57inject: true58}),59// copy custom static assets60new CopyWebpackPlugin([61{62from: path.resolve(__dirname, '../static'),63to: config.dev.assetsSubDirectory,64ignore: ['.*']65}66])67]68})6970module.exports = new Promise((resolve, reject) => {71portfinder.basePort = process.env.PORT || config.dev.port72portfinder.getPort((err, port) => {73if (err) {74reject(err)75} else {76// publish the new Port, necessary for e2e tests77process.env.PORT = port78// add port to devServer config79devWebpackConfig.devServer.port = port8081// Add FriendlyErrorsPlugin82devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({83compilationSuccessInfo: {84messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],85},86onErrors: config.dev.notifyOnErrors87? utils.createNotifierCallback()88: undefined89}))9091resolve(devWebpackConfig)92}93})94})959697