这是我的配置文件,它在所需的“dist”目录中捆绑和生成构建文件。但我想将其复制到其他位置。问题是 copyWebPackPlugin 在构建完成之前运行得更早一些。
const CleanWebpackPlugin = require('clean-webpack-plugin');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const buildAssets= require('./frontEndBuildAssets');
const CopyWebpackPlugin = require('copy-webpack-plugin')
var vendorJsFiles = buildAssets.buildConfig.vendorJs;
var frontEndStyles = buildAssets.buildConfig.frontEndStyles;
var customJsFiles = buildAssets.buildConfig.customJSFiles;
let pathsToClean = [
'dist/assets'
]
const frontEndBuildConfig = {
entry: {'vendorJs':vendorJsFiles,'customJs':customJsFiles,'frontEndStyles':frontEndStyles},
output: {
path: __dirname + '/dist/assets',
filename: '[name]Bundle.js',
publicPath: ''
},
module: {
rules: [
{
test: /\.css$/,
exclude: path.resolve(__dirname, 'node_modules'),
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{ loader: 'css-loader?sourceMap!sass-loader?sourceMap!', options: { minimize: true,sourceMap: true} }
]
}),
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './fonts'
}
}]
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(pathsToClean),
new HtmlWebpackPlugin({
template: './src/indexTemplate.html',
inject: true,
filename: 'index.html'
}),
new UglifyJsPlugin({
uglifyOptions: {
exclude: /(costing)/,
output: {
comments: false,
beautify: true
},
compress: {},
}
}),
new ExtractTextPlugin('frontEndStylesBundle.css'),
new CopyWebpackPlugin([{ from: path.resolve(__dirname,'import/importFromExcel.html'),
to:path.resolve(__dirname,'costing/assets/')}])
]
};
module.exports = [frontEndBuildConfig];
运行 webpack --mode development 后,我没有在所需位置获得任何文件。