This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/build/webpack.dev.conf.js

118 lines
4.0 KiB
JavaScript
Raw Normal View History

2019-11-28 18:23:49 +08:00
'use strict'
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
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')
2023-03-30 11:50:43 +08:00
// const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
2019-11-28 18:23:49 +08:00
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
const { VueLoaderPlugin } = require('vue-loader')
const intro = require('intro.js')
2019-11-28 18:23:49 +08:00
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT)
const devStart = process.env.npm_lifecycle_event
const indexHtml = devStart === 'dev' ? 'src/entrance/app/index.html' : 'src/entrance/exportHtml/exportHtml.html'
let devWebpackConfig = ''
2023-03-30 11:50:43 +08:00
// const smp = new SpeedMeasurePlugin()
devWebpackConfig = merge(baseWebpackConfig, {
2022-11-16 11:17:31 +08:00
mode: 'development',
2019-11-28 18:23:49 +08:00
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool,
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
historyApiFallback: true,
// historyApiFallback: {
// // rewrites: [
// // // { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, indexHtml) }
// // { from: /.*/, to: '/ui' },
// // { from: '/ui', to: path.posix.join(config.dev.assetsPublicPath, indexHtml) },
// // ]
// },
2019-11-28 18:23:49 +08:00
hot: true,
2022-05-05 10:36:00 +08:00
inline: true,
2019-11-28 18:23:49 +08:00
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
2022-04-11 15:49:10 +08:00
publicPath: '/',
/* publicPath: config.dev.assetsPublicPath, */
2019-11-28 18:23:49 +08:00
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
2022-04-11 15:49:10 +08:00
poll: config.dev.poll
2019-11-28 18:23:49 +08:00
}
},
plugins: [
new VueLoaderPlugin(),
new webpack.ProvidePlugin({
introJs: ['intro.js']
}),
2019-11-28 18:23:49 +08:00
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
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({
favicon: path.resolve(__dirname, '../src/assets/img/favicon.ico'),
2019-11-28 18:23:49 +08:00
filename: 'index.html',
template: indexHtml,
inject: true,
chunks: devStart === 'dev' ? ['app'] : ['exportHtml']
2019-11-28 18:23:49 +08:00
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*']
2022-04-11 15:49:10 +08:00
},
{
from: path.resolve(__dirname, '../src/components/chart'),
to: 'components/chart',
ignore: ['.*']
2019-11-28 18:23:49 +08:00
}
])
]
})
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port
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: {
2022-04-11 15:49:10 +08:00
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`]
2019-11-28 18:23:49 +08:00
},
onErrors: config.dev.notifyOnErrors
2022-04-11 15:49:10 +08:00
? utils.createNotifierCallback()
: undefined
2019-11-28 18:23:49 +08:00
}))
2023-03-30 11:50:43 +08:00
// devWebpackConfig = smp.wrap(devWebpackConfig)
2019-11-28 18:23:49 +08:00
resolve(devWebpackConfig)
}
})
})