Usage of css file separation plug-in (extract-text-webpack-plugin)
本篇文章给大家带来的内容是关于css文件实现分离的插件(extract-text-webpack-plugin)的用法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
css分离:extract-text-webpack-plugin
1、安装该插件:
for webpack 1
npm install –save-dev extract-text-webpack-plugin@1.0.1
for webpack 2
npm install –save-dev extract-text-webpack-plugin@2.1.2
for webpack 3
npm install –save-dev extract-text-webpack-plugin
for webpack 4
npm i extract-text-webpack-plugin@next -D
2、在webpack-config.js中引入插件
const extractTextPlugin=require(“extract-text-webpack-plugin”);
3、配置plugins:这里new一下这个对象,与上面那个配置插件用逗号分隔
new extractTextPlugin(“/css/index,.css”)
4、这里的/css/index.css是分离后的路径位置。这部配置完成后,包装代码:还要修改原来我们的style-loader和css-loader
-
[x] 修改代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module:{ rules: [
{
test: /\.css$/,
use
: extractTextPlugin.extract({
fallback:
"style-loader"
,
use
:
"css-loader"
})
},{ test:/\.(png|jpg|gif)/ ,
use
:[{
loader:'url-loader',
options:{
limit:500000
}
}]
}
]
},
Copy after login5、使用webpack进行打包
publicPath:是在webpack.config.js文件的output选项中,主要作用就是处理静态文件路径的
在处理前需要在webpack.config.js上方声明一个website对象
注意:这里的IP和端口是本机的ip或者是你devServer配置的IP和端口 //==publicPath里面的内内容一定要写正确:用ipconfig查看电脑的ip地址,然后冒号后面跟自己设置的端口==
注意:虽然把css文件分离出来了,但是css路径不对
用==publishPath==来解决
1
2
var
website={
publicPath:
"http://192.168.1.108:1717"
}
Copy after login6、在output选项中引用这个对象的publicPath属性
1
2
3
4
5
//出口文件的配置项output:{ //输出的路径,用了Node语法
path:path.resolve(__dirname,'dist'),
//输出的文件名称
filename:'[name].js',
publicPath:website.publicPath
},
Copy after login7、使用webpack进行打包,这时原来的相对路径就会变为绝对路径(绝对路径速度会更快)
*若出现下列错误,说明ip没写对
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
修改好正确的ip地址就可以运行成功了,哈哈
相关推荐:
The above is the detailed content of Usage of css file separation plug-in (extract-text-webpack-plugin). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
