当我使用--open标志启动webpack-dev-server时,如何激活它打开我的publicPath呢?
目前它会在浏览器中打开一个选项卡,指向http://localhost:3000,但是我希望它直接打开http://localhost:3000/app,这是我定义的public path。
当我手动输入webpack-dev-server启动后的http://localhost:3000/app时,它按预期工作。
这是我的webpack.config.js,目前运行良好:
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: {
vendor: [
'jquery',
'angular'
],
app: './src/app/index.module.js',
libs: [
'./src/libs/pagination/dirPagination.js',
'./src/libs/sc-date-time/sc-date-time.js',
'./src/libs/msd-elastic.js',
'./src/libs/ng-textcomplete.js',
'./src/libs/highcharts/highslide-full.js',
'./src/libs/highcharts/Sankey.js'
]
},
output: {
filename: '[name].bundle.js',
chunkFilename: '[id].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/app/'
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
host: 'localhost',
port: '3000',
inline: true,
compress: true,
proxy: {
'/api/**': {
target: 'http://10.189.1.159:8080',
secure: false,
changeOrigin: true,
cookieDomainRewrite: true
}
}
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
angular: path.resolve(__dirname, 'node_modules/angular/index.js')
}
},
module: {
rules: [{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader']
})
}, {
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{loader: 'css-loader', options: {sourceMap: true}},
{loader: 'postcss-loader', options: {sourceMap: true}},
{loader: 'sass-loader', options: {sourceMap: true}}
]
})
}, {
test: /\.ts|\.js?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}, {
test: /\.html$/,
use: [
{loader: 'ngtemplate-loader?relativeTo=' + (path.resolve(__dirname, 'src/app'))},
{loader: 'html-loader'}
],
exclude: path.resolve(__dirname, 'src/index.html')
}, {
test: /\.(jpe?g|gif|png|svg)$/,
use: [
{loader: 'file-loader?relativeTo=' + (path.resolve(__dirname, 'src/assets'))}
]
}, {
test: /.(ttf|otf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}]
}, {
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
}, {
loader: 'expose-loader',
options: '$'
}]
}, {
test: require.resolve('angular'),
use: [{
loader: 'expose-loader',
options: 'angular'
}]
}]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin('styles.css'),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
chunks: ['manifest', 'vendor', 'app', 'libs']
new CopyWebpackPlugin([{
context: './src/assets/locales',
from: '**/*',
to: './assets/locales/'
}])
]
};
--open
标志...该标志用于设置浏览器。根据文档,您需要类似--openPage
开关来在加载时导航到其他页面。如果这是您需要的。至于目录,除了从 contentBase 和 publicPath 提供服务之外,我不知道是否还有其他方法。 - mutantkeyboard