Answer the question
In order to leave comments, you need to log in
How to copy assets from node_modules to public directory using gulp or webpack?
I am developing an application in PHP, I am a dinosaur in front-end development. I have several libraries connected via npm. I need to copy some folders from node_modules to the project's public/assets folder while maintaining the subfolder structure. An example of folders that I want to copy:
- node_modules\vue\dist\
- node_modules\bootstrap\dist\
I want to get the following structure at the output:
- public/assets/vue/dist
- public/assets/bootstrap/dist
Tell me how to do this using gulp or webpack, preferably by purely available means, without additional plugins.
And what are the general practices for publishing assets? Basically, I meet assembly in just 1 file, examples are full of plugins, tutorials were written in different years and due to the rapid development of tools, the code presented there often does not work, so I have difficulty learning.
Answer the question
In order to leave comments, you need to log in
An example of part of the configuration for webpack version 4 (but also works on the previous ones):
output: {
path: resolve(__dirname, './dist'),
publicPath: mode === 'development' ? '/' : 'static/',
filename: '[name].js'
},
module: {
rules: [
{
test: /\.(png|jpg|jpeg|gif|svg|woff|ico|woff2|ttf|eot)(\?.*$|$)/,
loader: 'file-loader',
exclude: /node_modules/,
options: {
name: '[path][name].[ext]?[hash]',
publicPath: mode === 'development' ? '' : './static'
}
},
{
test: /\.(png|jpg|jpeg|gif|svg)(\?.*$|$)/,
loader: 'file-loader',
options: {
regExp: /node_modules/,
name: '[name].[ext]?[hash]',
publicPath: mode === 'development' ? '' : './static/img',
outputPath: 'static/img'
}
}
]
}
{
background: transparent url(./static/_/node_modules/fancybox/dist/img/blank.gif);
}
{
background: transparent url(./static/img/blank.gif);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question