You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
5.8 KiB
166 lines
5.8 KiB
'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')
|
|
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
|
|
const portfinder = require('portfinder')
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
|
|
|
const HOST = process.env.HOST
|
|
const PORT = process.env.PORT && Number(process.env.PORT)
|
|
|
|
const devWebpackConfig = merge(baseWebpackConfig, {
|
|
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',
|
|
// 404 页面配置
|
|
historyApiFallback: {
|
|
rewrites: [{
|
|
from: /.*/,
|
|
to: path.posix.join(config.dev.assetsPublicPath, 'index.html')
|
|
},],
|
|
},
|
|
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: config.dev.errorOverlay ? {
|
|
warnings: false,
|
|
errors: true
|
|
} : false,
|
|
publicPath: config.dev.assetsPublicPath,
|
|
proxy: config.dev.proxyTable,
|
|
quiet: true, // necessary for FriendlyErrorsPlugin
|
|
watchOptions: {
|
|
poll: config.dev.poll,
|
|
}
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// new BundleAnalyzerPlugin(),
|
|
|
|
// 自动加载模块,而不必到处 import 或 require
|
|
new webpack.ProvidePlugin({
|
|
// marked: "marked",
|
|
// $: 'jquery',
|
|
// jQuery: 'jquery',
|
|
_: 'lodash',
|
|
Popper: ['popper.js', 'default'],
|
|
utils: [path.join(__dirname, '..', 'src/utils'), 'default'],
|
|
}),
|
|
|
|
// 允许创建一个在编译时可以配置的全局常量
|
|
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
|
|
// 自动更新html中的入口文件
|
|
new HtmlWebpackPlugin({
|
|
filename: 'index.html', // html生成的文件 `/index.html`
|
|
template: 'src/index.html', // webpack模板 默认为src/index.ejs
|
|
inject: true, // 开启自动注入模块入口文件
|
|
favicon: path.resolve(__dirname, '../src/favicon.ico'),
|
|
title: 'Crypto | Exchange | Market',
|
|
isProduct : process.env.NODE_ENV == 'production' ? true : false,
|
|
}),
|
|
|
|
// split vendor js into its own file
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
name: 'vendor',
|
|
minChunks(module) {
|
|
// any required modules inside node_modules are extracted to vendor
|
|
return (
|
|
module.resource &&
|
|
/\.js$/.test(module.resource) &&
|
|
module.resource.indexOf(
|
|
path.join(__dirname, '../node_modules')
|
|
) === 0
|
|
)
|
|
}
|
|
}),
|
|
|
|
// extract webpack runtime and module manifest to its own file in order to
|
|
// prevent vendor hash from being updated whenever app bundle is updated
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
name: 'manifest',
|
|
minChunks: Infinity
|
|
}),
|
|
|
|
// This instance extracts shared chunks from code splitted chunks and bundles them
|
|
// in a separate chunk, similar to the vendor chunk
|
|
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
name: 'app',
|
|
async: 'vendor-async',
|
|
children: true,
|
|
minChunks: 3
|
|
}),
|
|
|
|
// 将单个文件或整个目录复制到构建目录。
|
|
// copy custom static assets,复制自定义静态资源
|
|
new CopyWebpackPlugin([{
|
|
from: path.resolve(__dirname, '../static'),
|
|
to: config.dev.assetsSubDirectory,
|
|
ignore: ['.*']
|
|
}]),
|
|
|
|
new CopyWebpackPlugin([{
|
|
from: path.resolve(__dirname, '../static/newProduct'),
|
|
to: config.dev.newProductRoot,
|
|
ignore: ['.*']
|
|
}]),
|
|
],
|
|
|
|
})
|
|
|
|
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: {
|
|
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
|
|
},
|
|
onErrors: config.dev.notifyOnErrors ?
|
|
utils.createNotifierCallback() : undefined
|
|
}))
|
|
|
|
resolve(devWebpackConfig)
|
|
}
|
|
})
|
|
})
|
|
|