[AngularJS + Webpack] Requiring CSS & Preprocessors
Making your CSS modular is a difficult thing to do, but using Webpack makes this so much easier. By adding a single line to your Webpack config, you can require you CSS, Stylus, Less, etc. files right from your directives and keep everything together.
Install:
npm install -D style-loader css-loader stylus-loader
webpack.config.js:
'style!css' means compile css first then style. The webpack read from right to left.
So 'style!css!stylus': compile stylus, then css, final style.
module.exports = {
entry: {
app: ['./app/index.js']
},
output: {
path: './build',
filename: 'bundle.js'
},
module: {
loaders: [
{test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/},
{test: /\.html$/, loader: 'html-loader', exclude: /node_modules/},
{test: /\.css$/, loader: 'style!css', exclude: /node_modules/},
{test: /\.css$/, loader: 'style!css!stylus', exclude: /node_modules/}
]
}
};
export default (ngModule) => {
ngModule.directive('hello', () => {
require('./hello.css');
return {
restrict: 'E',
scope: {},
template: require('./hello.html'),
controllerAs: 'vm',
controller: function() {
var vm = this;
vm.greeting = "Hello";
}
}
}) }
[AngularJS + Webpack] Requiring CSS & Preprocessors的更多相关文章
- [AngularJS + Webpack] Requiring Templates
With Angular, most of the time you're specifying a templateUrl for your directives and states/routes ...
- CSS预编译与PostCSS以及Webpack构建CSS综合方案
CSS全称Cascading Style Sheets(层叠样式表),用来为HTML添加样式,本质上是一种标记类语言.CSS前期发展非常迅速,1994年哈肯·维姆·莱首次提出CSS,1996年12月W ...
- webpack导入css及各项loader
1. webpack导入css 1) 下载相关的加载器 npm install style-loader css-loader -D 2)将index.css引入到mian.js中 import '. ...
- AngularJS动态设置CSS
使用AngularJS动态设置CSS大致有2种思路: 1.通过动态设置class名称 比如先定义2个样式: .show-true{ display:block;} .show-flase{ ...
- react&webpack使用css、less && 安装原则 --- 从根本上解决问题。
在webpack-react项目中,css的使用对于不同人有不同的选择,早起是推荐在jsx文件中使用 css inline js的,但是这种方法要写很多对象来表示一个一个的标签,并且对于这些对象,我们 ...
- webpack教程——css的加载
首先要安装css的loader npm install css-loader style-loader --save-dev 然后在webpack.config.js中配置如下代码 意思是先用css- ...
- Webpack打包css后z-index被重新计算的解决方法
发现问题 最近在使用 Webpack 打包 css 文件时,发现了一个问题,发现打包后的 z-index 值跟源文件 z-index 不一致. 如下图,左侧是源文件,右侧是打包后的文件: 即使加上 ! ...
- webpack抽取CSS文件与CSSTreeShaking
webpack抽取CSS文件 CSSTreeShaking 一.webpack抽取CSS文件 抽取CSS文件的插件:mini-css-extract-plugin npm install --save ...
- webpack 提取css成单独文件
webpack 提取css成单独文件 // 用来拼接绝对路径的方法 const {resolve} = require('path') const HtmlWebpackPlugin = requir ...
随机推荐
- PHPUnit测试
今天单元测试测到一个有点坑的小问题: public function testUpdataStatusFailForNegative() { // // Remove the following li ...
- js输出单一字符字串
<!DOCTYPE HTML> <html> <body> <input type="text" id="str" & ...
- 控制器view加载
出自李明杰讲课视频
- 简单学C——第四天
数组 在学数组之前,有必要把前面的知识复习一遍,当然我的复习,仅仅只是提一下,而对于你,则应该认真的看一下前面的知识点,不懂可以百度,哈哈. 前面我们大致学了 1.定义变量,2.数据的输入与输出,3. ...
- 各浏览器Cookie大小、个数限制
一.浏览器允许每个域名所包含的cookie数: Microsoft指出InternetExplorer8增加cookie限制为每个域名50个,但IE7似乎也允许每个域名50个cookie. Firef ...
- js 时间函数 及相关运算大全
js 时间函数 及相关运算大全 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); ...
- Android应用自杀和干掉其它进程
// 自杀(这种方式只能杀掉自己的进程,其它进程无法杀死) int pid = Process.myPid(); android.os.Process.killProcess(pid); // 或者 ...
- bzoj AC 50 庆祝~~
No. 1050 Solved 50 Submit 212 AC 60 PE 6 WA 88 TLE 13 MLE 5 OLE 2 RE 29 CE 9 10001002100310041005 10 ...
- Spring MVC 解读——<context:component-scan/>
转自:http://my.oschina.net/HeliosFly/blog/203149 作者:GoodLoser. Spring MVC 解读---<context:component-s ...
- 使用HttpServletRequestWrapper在filter修改request参数
javax.servlet.ServletRequest中的 Map<String, String[]> parameterMap = request.getParameterMap(); ...