Skip to content

Commit cb32fe6

Browse files
committed
webpack 处理 css
1 parent 3e5e6be commit cb32fe6

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

BuildTools/webpack-loader-es6/dist/js/main-bundle.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,28 @@
6969

7070
"use strict";
7171
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
72-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__components_layer_layer_js__ = __webpack_require__(1);
72+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__css_common_css__ = __webpack_require__(1);
73+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__css_common_css___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__css_common_css__);
74+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__components_layer_layer_js__ = __webpack_require__(2);
75+
7376

7477

7578
const App = function (){
7679
const NUM = 1;
7780
alert(NUM);
78-
console.log(__WEBPACK_IMPORTED_MODULE_0__components_layer_layer_js__["a" /* default */]);
79-
}
81+
console.log(__WEBPACK_IMPORTED_MODULE_1__components_layer_layer_js__["a" /* default */]);
82+
};
8083

8184
new App();
8285

8386
/***/ }),
8487
/* 1 */
88+
/***/ (function(module, exports) {
89+
90+
throw new Error("Module parse failed: /Users/zhangbing/github/CodeTest/BuildTools/webpack-loader-es6/src/css/common.css Unexpected token (1:9)\nYou may need an appropriate loader to handle this file type.\n| html,body{\n| padding: 0;\n| margin: 0;");
91+
92+
/***/ }),
93+
/* 2 */
8594
/***/ (function(module, __webpack_exports__, __webpack_require__) {
8695

8796
"use strict";
@@ -90,7 +99,7 @@ new App();
9099
function layer(){
91100
return {
92101
name: 'layer',
93-
tpl: tpl
102+
// tpl: tpl
94103
};
95104
}
96105

BuildTools/webpack-loader-es6/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
"author": "",
1111
"license": "ISC",
1212
"devDependencies": {
13+
"autoprefixer": "^7.1.2",
1314
"babel-preset-latest": "^6.24.1",
15+
"css-loader": "^0.28.5",
16+
"extract-text-webpack-plugin": "^3.0.0",
1417
"html-webpack-plugin": "^2.30.1",
18+
"postcss-loader": "^2.0.6",
19+
"style-loader": "^0.18.2",
1520
"webpack": "^3.5.5"
1621
}
1722
}
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import layer from './components/layer/layer.js'
1+
import './css/common.css';
2+
import layer from './components/layer/layer.js';
23

34
const App = function (){
45
const NUM = 1;
56
alert(NUM);
67
console.log(layer);
7-
}
8+
};
89

910
new App();

BuildTools/webpack-loader-es6/src/components/layer/layer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function layer(){
44
return {
55
name: 'layer',
6-
tpl: tpl
6+
// tpl: tpl
77
};
88
}
99

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
html,body{
2+
padding: 0;
3+
margin: 0;
4+
background-color: red;
5+
}
6+
7+
ul,li{
8+
list-style: none;
9+
padding: 0;
10+
margin: 0;
11+
}

BuildTools/webpack-loader-es6/webpack.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//https://www.npmjs.com/package/html-webpack-plugin
22
var htmlWebpackPlugin = require('html-webpack-plugin');
3+
var loaderOptionsPlugin = require('loader-options-plugin');
34
var path = require('path');
45

56
module.exports = {
7+
context: __dirname,//上下文
68
entry: './src/app.js',
79
output: {
810
path: __dirname+'/dist',
@@ -19,9 +21,18 @@ module.exports = {
1921
query:{
2022
presets: ['latest'] //也可以在package.js中配置或者.baelrtc中配置
2123
}
24+
},
25+
{
26+
test: '/\.css$/',
27+
loader: 'style-loader!css-loader?importLoaders=1!postcss-loader',
2228
}
2329
]
2430
},
31+
postcss: [
32+
require('autoprefixer')({
33+
broswers: ['last 5 version']
34+
})
35+
],
2536
plugins:[
2637
new htmlWebpackPlugin({
2738
filename: "index.html",

0 commit comments

Comments
 (0)