Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

javascript - 如何复制静态文件以使用Webpack构建目录?(How to copy static files to build directory with Webpack?)

I'm trying to move from Gulp to Webpack .(我正在尝试从Gulp迁移到Webpack 。)

In Gulp I have task which copies all files and folders from /static/ folder to /build/ folder.(在Gulp我的任务是将所有文件和文件夹从/ static /文件夹复制到/ build /文件夹。) How to do the same with Webpack ?(如何用Webpack做同样的Webpack ?) Do I need some plugin?(我需要一些插件吗?)   ask by Vitalii Korsakov translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Requiring assets using the file-loader module is the way webpack is intended to be used ( source ).(使用文件加载器模块来请求资产是打算使用webpack的方式( 来源 )。)

However, if you need greater flexibility or want a cleaner interface, you can also copy static files directly using my copy-webpack-plugin ( npm , Github ).(但是,如果您需要更大的灵活性或想要一个更copy-webpack-plugin界面,也可以使用我的copy-webpack-pluginnpmGithub )直接复制静态文件。) For your static to build example:(为您的static build示例:)
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    context: path.join(__dirname, 'your-app'),
    plugins: [
        new CopyWebpackPlugin([
            { from: 'static' }
        ])
    ]
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...