007sair / 007sair.github.io Goto Github PK
View Code? Open in Web Editor NEWBlog
Home Page: http://007sair.github.io
Blog
Home Page: http://007sair.github.io
@(webpack)
webpack-dev-server
无法实时刷新?
webpack.config.js
配置的scripts
项"scripts": {
"start": "webpack-dev-server --hot --inline"
}
webpack.config.js
的output
项内添加进行修改://指向异步加载的路径
publicPath: __dirname + '/build/'
替换为:
publicPath: '/build/'
npm start
为什么这样做呢?因为我们这前用webpack
是把组件异步加载在本地上,而我们用了热替换后是地址委托到了http://localhost:8080/
端口了,所以要去掉__dirname
(指向本地根目录),一切准备完毕了,接下来直接运行npm start
,然后打开http://localhost:8080/
就可以访问并实时刷新。
很多时候我们不喜欢require
进来的css或者sass被添加到html的style
标签中,而是作为单独的css文件被html引用。
extract-text-webpack-plugin
插件npm install extract-text-webpack-plugin --save-dev
webpack.config.js
//a.先require进来
var ExtractTextPlugin = require("extract-text-webpack-plugin");
//b.再添加到plugins中
plugins: [
new ExtractTextPlugin("styles.css")
]
module
的loaders
配置//需要知道的是,ExtractTextPlugin.extract 第二个参数(或拆分为多个参数)中 loader 的执行顺序是从右到左,即先对引入的 .sass 使用 sass loader 得到编译后的 css 再使用 css-loader 按照正常 css-loader 的方式处理。
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
}
]
参考:http://webpack.github.io/docs/stylesheets.html#separate-css-bundle
未解决。
正常开发时我们会这么设置字体:
.wrap{
font-family: "微软雅黑"; /* 或者 */
font-family: "\5FAE\8F6F\96C5\9ED1";
}
执行 npm run build
后,字体没生效,F12查看发现代码变成这样了:
.wrap{
font-family: \\5FAE\8F6F\96C5\9ED1;
}
修改方法:
.wrap{
font-family: \5FAE\8F6F\96C5\9ED1; /* 去掉双引号! */
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.