Last active
April 12, 2021 14:57
-
-
Save Sudheer-Reddy/5a0d8b8752e202ae1adecf360f9cf478 to your computer and use it in GitHub Desktop.
Copy static assets in Webpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Hi,
The plugin must be initialized with "patterns" property: