Skip to content

Commit

Permalink
commoncss, autoprefixer 自动加上浏览器前缀
Browse files Browse the repository at this point in the history
  • Loading branch information
yyccQQu committed Jan 29, 2019
1 parent bd5975e commit 669dd9a
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 51 deletions.
24 changes: 23 additions & 1 deletion build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,36 @@ eval("console.log(\"a.js\")\n\n//# sourceURL=webpack:///./src/a.js?");

/***/ }),

/***/ "./src/index.css":
/*!***********************!*\
!*** ./src/index.css ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack:///./src/index.css?");

/***/ }),

/***/ "./src/index.js":
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

eval("console.log(1)\nlet str = __webpack_require__(/*! ./a.js */ \"./src/a.js\")\n\n\n\n//# sourceURL=webpack:///./src/index.js?");
eval("console.log(1)\nlet str = __webpack_require__(/*! ./a.js */ \"./src/a.js\")\n__webpack_require__(/*! ./index.css */ \"./src/index.css\")\n__webpack_require__(/*! ./index.less */ \"./src/index.less\")\n\n//# sourceURL=webpack:///./src/index.js?");

/***/ }),

/***/ "./src/index.less":
/*!************************!*\
!*** ./src/index.less ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack:///./src/index.less?");

/***/ })

Expand Down
8 changes: 2 additions & 6 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head><style>
body {
<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><link href=main.css?0e0511d429e2874fbc68 rel=stylesheet></head><style>body {
background: pink
}
</style><body>
<div>12345</div>
<script type=text/javascript src=bundle.js?35f42786db5465f0e2d3></script></body></html>
}</style><body><div>12345</div><script type=text/javascript src=bundle.js?0e0511d429e2874fbc68></script></body></html>
11 changes: 11 additions & 0 deletions build/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
font-size: 16px;
background: red;
}
body {
background: #faf;
}
body div {
border: 1px solid #fdafaf;
}

65 changes: 65 additions & 0 deletions history/webpack.config.1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
let path = require("path");
let HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
devServer: {
// 开发服务器配置 webpack-dev-server
// 起服务构建的时候需要html文件,否则不会显示页面,只会显示路径
port: 3000,
progress: true,
contentBase: "./build"
},

mode: "development",
entry: "./src/index.js",
output: {
filename: "bundle.js", //打包后的文件名
path: path.resolve(__dirname, "./build") // 路径必须是一个绝对路径
},

plugins: [
// 所有webpack 插件
new HtmlWebpackPlugin({
template: "./src/index.html", //模板
filename: "index.html", //文件名
hash: true,
minify: {
// 压缩
removeAttributeQuotes: true, //删除属性双引号
collapseWhitespace: true //折叠为一行
}
})
],
module: {
rules: [
// 规则 css-loader 解析 @import语法
{
test: /.css$/,
// 多个loader 需要 [],从右向左执行
use: [
// loader 变为对象之后可以多传参数
{
loader: "style-loader",
options: { //将样式插入顶部,优先级为最小
insertAt: 'top'
}
},
"css-loader"
]
},
{
test: /.less$/,
use: [
{
loader: "style-loader",
options: {
insertAt: 'top'
}
},
"css-loader",
"less-loader" //从右至左加载
]
}
]
}
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
"dev": "webpack-dev-server"
},
"devDependencies": {
"autoprefixer": "^9.4.7",
"css-loader": "^2.1.0",
"html-webpack-plugin": "^3.2.0",
"postcss-loader": "^3.0.0",
"style-loader": "^0.23.1",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
},
"dependencies": {
"less": "^3.9.0",
"less-loader": "^4.1.0"
"less-loader": "^4.1.0",
"mini-css-extract-plugin": "^0.5.0"
}
}
1 change: 1 addition & 0 deletions src/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body{
div{
border: 1px solid #fdafaf;
transform: rotate(45deg);
}
}
66 changes: 25 additions & 41 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,49 @@
let path = require("path");
let HtmlWebpackPlugin = require("html-webpack-plugin");
let MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
devServer: {
// 开发服务器配置 webpack-dev-server
// 起服务构建的时候需要html文件,否则不会显示页面,只会显示路径
port: 3000,
progress: true,
contentBase: "./build"
},

mode: "development",
entry: "./src/index.js",
output: {
filename: "bundle.js", //打包后的文件名
path: path.resolve(__dirname, "./build") // 路径必须是一个绝对路径
filename: "bundle.js",
path: path.resolve(__dirname, "./build")
},

plugins: [
// 所有webpack 插件
new HtmlWebpackPlugin({
template: "./src/index.html", //模板
filename: "index.html", //文件名
template: "./src/index.html",
filename: "index.html",
hash: true,
minify: {
// 压缩
removeAttributeQuotes: true, //删除属性双引号
collapseWhitespace: true //折叠为一行
removeAttributeQuotes: true,
collapseWhitespace: true
}
}),
//把公用的css抽用成一个css文件
new MiniCssExtractPlugin({
filename: "main.css"
})
],
module: {
rules: [
// 规则 css-loader 解析 @import语法
{
test: /.css$/,
// 多个loader 需要 [],从右向左执行
use: [
// loader 变为对象之后可以多传参数
{
loader: "style-loader",
options: { //将样式插入顶部,优先级为最小
insertAt: 'top'
}
},
"css-loader"
]
},
{
test: /.less$/,
use: [
{
loader: "style-loader",
options: {
insertAt: 'top'
}
},
"css-loader",
"less-loader" //从右至左加载
]
}
MiniCssExtractPlugin.loader,
"postcss-loader", //autoprefixer 自动加上浏览器前缀
"css-loader"
]
},
{
test: /.less$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"less-loader"
]
}
]
}
};
Loading

0 comments on commit 669dd9a

Please sign in to comment.