Fix webpack-dev-server

This commit is contained in:
Pig Fang 2019-09-20 19:43:51 +08:00
parent 74452a70de
commit c0d6256efd
2 changed files with 468 additions and 255 deletions

View File

@ -1,4 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
const fs = require('fs')
const webpack = require('webpack') const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin') const VueLoaderPlugin = require('vue-loader/lib/plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin')
@ -138,7 +139,6 @@ const config = {
'resources/assets/src/images/bg.jpg', 'resources/assets/src/images/bg.jpg',
'resources/assets/src/images/favicon.ico', 'resources/assets/src/images/favicon.ico',
]), ]),
new ManifestPlugin(),
], ],
resolve: { resolve: {
extensions: ['.js', '.ts', '.vue', '.json'], extensions: ['.js', '.ts', '.vue', '.json'],
@ -150,15 +150,29 @@ const config = {
}, },
host: '0.0.0.0', host: '0.0.0.0',
hot: true, hot: true,
hotOnly: true,
public: getDevServerUrl(),
stats: 'errors-only', stats: 'errors-only',
}, },
stats: 'errors-only', stats: 'errors-only',
} }
if (devMode) { if (devMode) {
config.plugins.push(new webpack.NamedModulesPlugin())
config.plugins.push(new webpack.HotModuleReplacementPlugin()) config.plugins.push(new webpack.HotModuleReplacementPlugin())
} else { } else {
config.plugins.push(new WebpackBar()) config.plugins.push(new WebpackBar())
config.plugins.push(new ManifestPlugin())
} }
module.exports = config module.exports = config
function getDevServerUrl() {
const matches = /ASSET_URL=(.*)/.exec(fs.readFileSync('.env', 'utf8'))
if (!matches) {
return
}
const url = new URL(matches[1])
return `${url.host}:8080`
}

707
yarn.lock

File diff suppressed because it is too large Load Diff