tags: webpack
Note: Before installing, make sure the webpack project works properly!
cnpm i file-loader -D
module.exports = {
// ...
module:{
rules:[
// ...
{
test: /.(png|jpg|gif|jpeg)$/,
use:'file-loader'
}
]
}
}
import ReactDom from 'react-dom';
import './search.css';
import './search.less';
Import logo from './img/logo.jpg'; // introduction
class Search extends React.Component {
render() {
return <div className="search-txt">
Search Text
<img src={ logo } /> // use
</div>;
}
};
ReactDom.render(
<Search/>,
document.getElementById('root')
);
In fact, the two functions are similar. The url-loader is actually packaged on the basis of the file-loader, and the base64 conversion is automatically performed for the picture and font files of the limit size.
cnpm i url-loader -D
module.exports = {
// ...
module:{
rules:[
// ...
{
test: /.(png|jpg|gif|jpeg)$/,
use:[
{
loader: 'url-loader',
options:{
Limit: 10240 // The unit of limit is byte. Only when it is less than 10k, it is allowed to automatically transfer to base64.
}
}
]
}
]
}
}
Article Directory Install the loader related to the vue file webpack about Vue related configuration Define the main.js startup file and load the App.vue file Install the loader related to the vue fil...
Installation webpack Webpack command execution npx command that the implementation of the project in webpack node_modules commands executed directly webpack otherwise, you will need to install a globa...
Webpack is written in JS and runs in a node environment, so by default, only the dependencies between JS will be processed when webpack is packaged! ! ! If you don’t believe it, you can create a...
Original address:Detailed webpack loader and plugin First, the common configuration of webpack Second, the packaging principle of webpack Identify entry files By layer-by-layer identification o...
Interview questions: Do you know the principle of webpack? What configuration did we use webpack in your project? What is the difference between loader and plugin? What are used in the project? 【Loade...
contents File structure Solution File structure I set two DIVs on the page to display the background image, the picture is introduced by the LESS file inside SRC / CSS. Configure the following c...
I. Introduction Second, install the configuration picture related loader and prepare the picture Install url-loader and file-loader: Check the package.json file after installation Related documents: h...
1 Introduction If we want to introduce the picture page (including the url img src and the background). When we webpack-based development, the introduction of the picture will encounter some problems....
Foreword: This article introduces url-loader (enhanced file-loader); The role of url-loader: selectively encode some small pictures into base64 format and write them into the page according to the dem...
You can see that the url-loader is used for image compilation, and some people use file-laoder, so what is the difference between the two? Which one should I use? url-loader: Function: The function of...