我有兩個佈局(LayoutWithShortHeader,TestLayout)和這樣的路線:隔離風格不同的佈局(的WebPack,反應)
export default (
<Router history={createBrowserHistory()}>
<Route path="/" component={ LayoutWithShortHeader }>
<IndexRoute component={ Index }/>
</Route>
<Route path="/" component={ TestLayout }>
<Route path="ddd" component={ TestPage }/>
<Route path="not-found" component={ NotFound }/>
</Route>
<Redirect from="*" to="/not-found"/>
</Router>
);
當我打開/ DDD的頁面由TestLayout與TestPage裏面。 不幸的是,它有LayoutWithShortHeader(導入'./layout.sass';內部LayoutWithShortHeader)的樣式,我不知道爲什麼。
TestLayout.jsx:
'use strict';
import React from 'react';
const TestLayout = React.createClass({
propTypes: {
children: React.PropTypes.object
},
getInitialState() {
return {};
},
render() {
return (
<div>
{ this.props.children }
</div>
);
}
});
export default TestLayout;
的WebPack CONFIGS:
webpack.common.config.js:
'use strict';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Sprites = require('sprite-webpack-plugin');
const autoprefixer = require('autoprefixer');
module.exports = {
module: {
loaders: [
{
test: /\.(js|jsx)$/,
include: path.join(__dirname, 'src'),
loaders: ['react-hot', 'babel', 'eslint']
},
{
test: /\.css$/,
loaders: ['style', 'css']
},
{
test: /\.sass$/,
loaders: ['style', 'css', 'postcss', 'sass?indentedSyntax']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader'
},
{
test: require.resolve('jquery'),
loader: 'expose?jQuery'
},
{
test: require.resolve('jquery'),
loader: 'expose?$'
}
]
},
postcss: function() {
return [autoprefixer({ browsers: ['last 3 versions'] })];
},
devtool: 'source-map',
resolve: {
extensions: ['', '.js', '.jsx', '.json']
},
plugins: [
new HtmlWebpackPlugin({
title: 'Netology',
template: './src/index.html',
scriptFilename: 'application.js'
}),
new Sprites({
'source': __dirname + '/src/images/for_sprites/',
'imgPath': __dirname + '/src/images/',
'cssPath': __dirname + '/src/stylesheets/',
'multiFolders': true
})
],
resolve: {
root: path.resolve(__dirname),
alias: {
js: 'src/javascripts',
fonts: 'src/fonts',
components: 'src/components'
},
extensions: ['', '.js', '.jsx', '.sass']
}
};
webpack.config.js: '使用嚴格';
const path = require('path');
const webpack = require('webpack');
const friendlyFormatter = require('eslint-friendly-formatter');
let config = require('./webpack.common.config');
config.entry = [
'webpack-dev-server/client?http://0.0.0.0:3000',
'webpack/hot/only-dev-server',
'./src/javascripts/main.js'
];
config.output = {
path: path.join(__dirname, 'build'),
filename: 'application.js',
publicPath: '/'
};
config.eslint = {
formatter: friendlyFormatter
};
config.plugins.push(
new webpack.NoErrorsPlugin(),
new webpack.HotModuleReplacementPlugin()
);
module.exports = config;
那麼如何從另一個樣式中分離一個佈局的樣式?
可以請你分享一下webpack.config文件。不用看你如何捆綁樣式。它很難知道正確的原因。 – sandeep
添加了webpack config – dortonway
您可以嘗試在普通webpack配置中的* css *之前和* postcss之後添加''localIdentName = [name] - [local]'',看看會發生什麼。 – sandeep