有汇编...
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpackConf = {
entry: './frontend/app/app.js',
output: {
path: path.resolve(__dirname, './production'),
filename: 'bundle.js',
publicPath: 'production/'
},
devServer: {
port: 80,
overlay: true,
},
plugins: [
new HtmlWebpackPlugin({
filename: './index.html', // Комментарий №1
template: './frontend/main_pages/tamplate_en.html',
title: "Index"
}),
new CleanWebpackPlugin()
]
};
module.exports = () => {
return webpackConf;
};
一切正常,但是一旦我更改创建路径index.html
(请参阅代码中上面的注释#1),publicPath: 'production/'
它就看不到index.html
我没试过的
publicPath: '生产/主页/'
publicPath: '主页/'
这就是我得到的...
我想出的唯一一件事就是改变创建路径index.html
当production
您设置一条路径时,当development
另一条...
这是正确的解决方案,还是有更简单的方法来解决这个问题?
补充...
生产程序集将转到此文件夹
路径:path.resolve(__dirname, './production'),
如果我有插件
new HtmlWebpackPluginindex.html
在根目录创建production文件夹,然后一切正常,但我需要new HtmlWebpackPlugin 来创建production/main-pages/index.html
文件夹
所以,当index.html
不在production文件夹的根目录下,而是在production/main-pages/文件夹中时, devServer 看不到index.html
,`publicPath: 'production/' 不起作用
了解
devServer
主要在哪里index.html
publicPath: '/'
必须指定项目根目录devServer:
必须添加到contentBase: path.join(__dirname, 'production')
指向构建文件夹openPage: 'main-pages/en/index.html'
明确指定要运行的文件openPage:
您可以指定多个文件的数组openPage: ['main-pages/en/index.html', 'main-pages/ru/index.html', 'main-pages/ge/index.html']