Skip to content

Instantly share code, notes, and snippets.

@rbngzlv
Forked from Sudheer-Reddy/webpack.config.js
Created June 26, 2019 17:16
Show Gist options
  • Save rbngzlv/9c445dc20deb21f0b8c011e7d40e663b to your computer and use it in GitHub Desktop.
Save rbngzlv/9c445dc20deb21f0b8c011e7d40e663b to your computer and use it in GitHub Desktop.
Copy static assets in Webpack
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const PATHS = {
src: path.join(__dirname, 'src'), //absolute path to RepoDir/src
dist: path.join(__dirname, 'dist') //absolute path to RepoDir/dist
}
module.exports = {
entry: {
//Webpack will automatically resolve it to RepoDir/src/js/index.js (if file name is not specified)
//main: PATHS.src + '/js/app.js' //Webpack will resolve it to RepoDir/src/js/app.js
main: PATHS.src + '/js'
},
output: {
//Will resolve to RepoDir/dist
path: PATHS.dist,
//[name] is placeholder for entry ie.. main from line `12`
//So output file name will be main<somehash>.js
filename: 'js/[name][hash].js'
},
plugins: [
new CopyWebpackPlugin([
{
//Note:- No wildcard is specified hence will copy all files and folders
from: 'src/assets', //Will resolve to RepoDir/src/assets
to: 'assets' //Copies all files from above dest to dist/assets
},
{
//Wildcard is specified hence will copy only css files
from: 'src/css/*.css', //Will resolve to RepoDir/src/css and all *.css files from this directory
to: 'css'//Copies all matched css files from above dest to dist/css
}
])
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment