gpt4 book ai didi

javascript - copy-webpack-plugin 不复制文件

转载 作者:数据小太阳 更新时间:2023-10-29 05:34:43 25 4
gpt4 key购买 nike

我尝试只复制文件来检查简单的 webpack 配置。所以我一直在尝试让 copy-webpack-plugin 工作——没有任何反应:没有复制的文件,没有错误,什么都没有

常用配置(webpack.common.js):

const path = require('path');

const CopyWebpackPlugin = require('copy-webpack-plugin');

const postCssPlugin = [
require('postcss-import'),
require('postcss-nested'),
require('postcss-simple-vars'),
require('autoprefixer')({
browsers: [
'last 3 versions',
'android 4.2'
]
})
];

module.exports = {
context: path.resolve(__dirname, '../src'),
entry: [
'babel-polyfill',
path.resolve(__dirname, '../src/index.js')
],
output: {
path: path.resolve(__dirname, '../dist/js'),
publicPath: '',
filename: 'app.js'
},
resolve: {
extensions: ['.jsx', '.js', '.json']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.p?css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: postCssPlugin
}
}
]
}
]
},
plugins: [
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../src/assets/**/*'),
to: path.resolve(__dirname, '../dist/assets'),
flatten: true
}
])
],
stats: {
modules: true,
warnings: false,
version: true,
timings: true,
performance: false,
hash: true,
errors: true,
errorDetails: true,
colors: true,
builtAt: true
}
};

webpack.prod.js:

const commonWebpackConfig = require('./webpack.common.js');

const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin');

module.exports = Object.assign(commonWebpackConfig, {
mode: 'production',
plugins: [
new UglifyJsWebpackPlugin({
sourceMap: true
})
]
});

并构建起始文件 build.js:

const webpack = require('webpack');

const webpackProdConfig = require('./webpack.config/webpack.prod.js');

webpack(webpackProdConfig, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(err.stack || err);
}

console.log('Successfully compiled!');
});

所以有人能弄清楚为什么它不起作用以及我哪里错了吗?复制 webpack 插件:4.5.2节点:9.1.0npm:6.3.0 window :10

添加 - 文件夹结构:

enter image description here

最佳答案

尝试从 dist 文件夹复制。对我来说它有效es.

new CopywebpackPlugin([{
from: path.resolve(__dirname, 'node_modules/mettrr-component-library/dist/img'),
to: path.resolve(__dirname, 'src/assets/img')
}]),

关于javascript - copy-webpack-plugin 不复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52478834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com