Webpack 开始使用网页包的手写笔加载程序
好吧(这是新的): 我刚刚将我的Webpack 开始使用网页包的手写笔加载程序,webpack,Webpack,好吧(这是新的): 我刚刚将我的手写笔加载器,样式加载器(按照手写笔加载器的建议)和加载器{test:/\.styl$/,加载器:'style loader!css loader!stylus loader'}添加到网页配置中。现在在Main.js文件中,我添加了var css=require('!css!stylus!/Main.styl')。那么,我现在应该在html中看到已编译的css吗?我不确定我是否做对了 webpack.config.js webpackConfig = {
手写笔加载器
,样式加载器
(按照手写笔加载器
的建议)和加载器{test:/\.styl$/,加载器:'style loader!css loader!stylus loader'}添加到网页配置中。现在在Main.js文件中,我添加了var css=require('!css!stylus!/Main.styl')代码>。那么,我现在应该在html中看到已编译的css吗?我不确定我是否做对了
webpack.config.js
webpackConfig = {
context: __dirname,
entry: {
app: ['webpack/hot/dev-server','./index.js']
},
output: {
path: __dirname,
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
]
}
}
module.exports = webpackConfig;
var React = require('react');
var Main = require('./App/Components/Main');
class App extends React.Component{
render(){
return (
<Main />
)
}
}
React.render(<App />, document.getElementById('main'));
'use strict'
import React from 'react';
import ReactCanvas from 'react-canvas';
var css = require('!css!stylus!./Main.styl');
var {
Surface
} = ReactCanvas;
class Main extends React.Component{
constructor() {
super();
this.size = document.getElementById('main').getBoundingClientRect()
}
render() {
return (
<Surface top={0} left={0} width={this.size.width} height={this.size.height}>
</Surface>
)
}
}
module.exports = Main
index.js
webpackConfig = {
context: __dirname,
entry: {
app: ['webpack/hot/dev-server','./index.js']
},
output: {
path: __dirname,
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
]
}
}
module.exports = webpackConfig;
var React = require('react');
var Main = require('./App/Components/Main');
class App extends React.Component{
render(){
return (
<Main />
)
}
}
React.render(<App />, document.getElementById('main'));
'use strict'
import React from 'react';
import ReactCanvas from 'react-canvas';
var css = require('!css!stylus!./Main.styl');
var {
Surface
} = ReactCanvas;
class Main extends React.Component{
constructor() {
super();
this.size = document.getElementById('main').getBoundingClientRect()
}
render() {
return (
<Surface top={0} left={0} width={this.size.width} height={this.size.height}>
</Surface>
)
}
}
module.exports = Main
var React=require('React');
var Main=要求('./App/Components/Main');
类应用程序扩展了React.Component{
render(){
返回(
)
}
}
React.render(,document.getElementById('main'));
Main.js
webpackConfig = {
context: __dirname,
entry: {
app: ['webpack/hot/dev-server','./index.js']
},
output: {
path: __dirname,
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
]
}
}
module.exports = webpackConfig;
var React = require('react');
var Main = require('./App/Components/Main');
class App extends React.Component{
render(){
return (
<Main />
)
}
}
React.render(<App />, document.getElementById('main'));
'use strict'
import React from 'react';
import ReactCanvas from 'react-canvas';
var css = require('!css!stylus!./Main.styl');
var {
Surface
} = ReactCanvas;
class Main extends React.Component{
constructor() {
super();
this.size = document.getElementById('main').getBoundingClientRect()
}
render() {
return (
<Surface top={0} left={0} width={this.size.width} height={this.size.height}>
</Surface>
)
}
}
module.exports = Main
“严格使用”
从“React”导入React;
从“react canvas”导入react canvas;
var css=require('!css!stylus!。/Main.styl');
变量{
表面
}=帆布;
类Main扩展了React.Component{
构造函数(){
超级();
this.size=document.getElementById('main').getBoundingClientRect()
}
render(){
返回(
)
}
}
module.exports=Main
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React Canvas</title>
</head>
<body>
<header>
<h1>React Canvas</h1>
</header>
<div id="main"></div>
<script src="http://localhost:8080/webpack-dev-server.js"></script>
<script src="bundle.js"></script>
</body>
</html>
反应帆布
反应帆布
您可以替换
var css = require('!css!stylus!./Main.styl');
与
感谢您的设置
默认情况下,CSS将转换为JavaScript并包含在JavaScript包中
我希望这有帮助。检查我的配置
我可以得到手写笔和邮政编码工作与内联风格
但是我不知道如何将bundle.css绑定到
<link rel=stylesheet />
您将“排除”拼错为“EXCULD”
顺便说一句():
“不幸的是,PostStylus用于传回后处理css的触控笔结束事件不接受回调,因此在修补此错误之前,上游PostStylus无法使用异步后处理css。”
我必须为使用lostcs(postsss网格)创建单独的文件,我只使用网格导入了这些文件(每个组件都有自己的style.styl文件和lost.css文件)。为我工作。复制和粘贴代码很糟糕:你在写代码的任何地方都拼错了exclude
。