Created
April 24, 2018 11:23
-
-
Save guilhermehn/951fc92d976f515a1f5555abb252d508 to your computer and use it in GitHub Desktop.
url-loader example
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
body { | |
/* | |
- image path should be relative | |
- taken from http://placehold.it/100x100 | |
*/ | |
background-image: url('./100x100.png'); | |
} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script src="./build/main.js"></script> | |
</body> | |
</html> |
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
import './index.css'; |
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
{ | |
"name": "url-loader-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "webpack && serve" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"css-loader": "^0.28.11", | |
"serve": "^6.5.6", | |
"style-loader": "^0.21.0", | |
"url-loader": "^1.0.1", | |
"webpack": "^4.6.0", | |
"webpack-cli": "^2.0.15" | |
} | |
} |
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 path = require('path'); | |
module.exports = { | |
mode: 'development', | |
entry: './index.js', | |
output: { | |
path: path.resolve(__dirname, './build'), | |
filename: '[name].js', | |
publicPath: '/' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.css$/, | |
// parse css imports and then pass it's | |
// results to style-loader to create a style | |
// tag when the script is loaded by the browser | |
loader: ['style-loader', 'css-loader'] | |
}, | |
{ | |
test: /\.(png|jpe?g|gif)$/, | |
loader: 'url-loader', | |
options: { | |
limit: 1000 | |
} | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment