Hướng dẫn webpack css - webpack css
Ngày đăng:
19/11/2022
Trả lời:
0
Lượt xem:
12
Show
Cài đặt và setting Webpack css loader
Loading CSS
Nội dung file |
Kết quả | Chỉnh lại file const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: {
newfile: [
'./src/index.js',
'./src/my-test.js'
]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Output Management'
})
],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
}
}; 0 với nội dung sau: |
---|---|
Tiến hành chạy lệnh npm để thực thi nội dung trên: | cd Webpack-project npm init -y npm install --save-dev webpack npm install --save-dev webpack-cli |
Khi này click chạy file npm install --save-dev style-loader css-loader3 ta thấy nội dung bên trong npm install --save-dev style-loader css-loader4 đã được gọi: | npx webpack |
Lúc này xem lại nội dung bên trong npm install --save-dev style-loader css-loader3 vẫn không có gì thay đổi. | npx webpack --config webpack.config.js npm run build |
Các lệnh chính đã sử dụng trong toàn bộ bài học | npm run build |
Bài học | npm install --save lodash npm run build npm run build |
Lệnh đã dùng | npm install --save-dev html-webpack-plugin npm run build |
Cài đặt Webpack | import './style.css';
function component() {
const element = document.createElement('div');
element.innerHTML = 'Hello World!';
return element;
}
document.body.appendChild(component()); 0
|
Webpack bundle | import './style.css';
function component() {
const element = document.createElement('div');
element.innerHTML = 'Hello World!';
return element;
}
document.body.appendChild(component()); 1
|
Cấu hình Webpack | npm run build |
Webpack quản lý output | import './style.css';
function component() {
const element = document.createElement('div');
element.innerHTML = 'Hello World!';
return element;
}
document.body.appendChild(component()); 1
|
Webpack code splitting | import './style.css';
function component() {
const element = document.createElement('div');
element.innerHTML = 'Hello World!';
return element;
}
document.body.appendChild(component()); 4
|