【发布时间】:2020-06-01 05:37:58
【问题描述】:
我正在尝试在 netlify 上部署我的网站。但是每次我运行 npm run build 时都不会创建任何构建文件夹。
"build": "webpack --mode production"
是我正在使用的命令
我得到了要部署的站点,但是我已经在这上面卡了好几个小时了,有人可以帮忙吗?
webpack 文件如下。
显然 webpack 构建了 dist 文件夹而不是 build 文件夹,所以我将设置我的 netlify 以将目录发布到它并看看会发生什么
更新成功了!
const HtmlWebPackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack');
// const outputPath = path.join(__dirname, "dist");
const extractSass = new ExtractTextPlugin({
filename: '[name].[hash].css',
disable: process.env.NODE_ENV === 'development',
});
module.exports = {
mode: 'production',
entry: { app: './src/index.js' },
output: {
filename: '[name].[hash].js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(png|jpg|gif)$/,
// exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: "[path]/[name].[ext]",
outputPath: './assets/img/',
context: 'src/assets/img/',
},
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 70,
},
// optipng.enabled: false will disable optipng
optipng: {
enabled: false,
},
pngquant: {
quality: '70-90',
speed: 4,
},
gifsicle: {
interlaced: false,
},
// the webp option will enable WEBP
webp: {
quality: 75,
},
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
loader: 'file-loader',
options: {
name: "./[name].[ext]",
outputPath: './assets/fonts/'
},
},
{
test: /\.html$/,
exclude: /node_modules/,
use: [
{
loader: 'html-loader',
options: { minimize: true },
},
],
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: extractSass.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
// use style-loader in development
fallback: 'style-loader',
}),
},
{
test: /\.css$/,
use: extractSass.extract({
fallback: 'style-loader',
use: 'css-loader',
}),
},
],
},
devServer: {
contentBase: './dist',
historyApiFallback: true,
hot: true
},
plugins: [
extractSass,
// new ExtractTextPlugin('[name].[hash].css'),
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html',
}),
new CleanWebpackPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
},
};
【问题讨论】:
-
你创建了自己的 webpack 配置了吗?如果是这样,最好在此处分享您的
webpack.config文件。 -
您在运行实时站点时遇到了什么问题?同样在构建期间,netlify 是否报告了任何问题?
-
你把它移到哪个目录来修复它?你还在 netlify 中使用什么构建命令?