Webpack - " css-loader / locals" miss为server.build和client.build匹配

时间:2017-05-19 08:28:01

标签: reactjs webpack css-loader

我设置了一个webpack配置来构建server.build和client.build,但它们都生成不同的css / locals。

  

webpack.server.js



const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');


const serverConfig = {
    name: 'server',
    target: 'node',
    externals: [nodeExternals()],
    entry: [
        __dirname+'/index.js'
    ],
    output: {
        path: path.join(__dirname, '/.build'),
        filename: 'server.build.js',
        publicPath: '.build/',
        libraryTarget: 'commonjs2'
    },
    module: {
        loaders: [
            {
                test:/\.(?:js|jsx)$/,
                exclude: /node_modules/,
                use: 'babel-loader',
            },
            {
                test: /\.(?:css|less)$/,
                use: "css-loader/locals?import=1&modules=1&localIdentName=[name]__[local]__[hash:base64:7]",
                exclude: /\.(eot|woff|woff2|ttf|svg)(\?[\s\S]+)?$/
            },
            {
                test: /\.(eot|woff|woff2|ttf|svg)(\?[\s\S]+)?$/,
                loader: 'url-loader?limit=1000&name=./fonts/[name].[ext]?[hash:base64:5]#icomoon',
            }
        ]
    },
    resolve: {
        extensions: ['.jsx', '.js', '.json','.less']
    }
};

module.exports = serverConfig;




  

webpack.client.js



const webpack = require('webpack');
const path = require('path');
const context = path.resolve(__dirname, 'src');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

const config = {
    name:"client",
    context,
    entry: __dirname+'/src/app.js',
    output: {
        path: __dirname+"/.build/assets",
        filename: 'bundle.js'
    },
    devtool: "source-map",
    module: {
        rules: [
            {
                test:/\.(?:js|jsx)$/,
                exclude: /node_modules/,
                use: 'babel-loader',
            },
            {
                test: /\.(?:css|less)$/,
                use: ExtractTextPlugin.extract({
                    use: [
                        {
                            loader: 'css-loader?module',
                            options: {
                                sourceMap: true,
                                importLoader: true,
                                localIdentName:'[name]__[local]__[hash:base64:7]'
                            }
                        },
                        {
                            loader: 'less-loader',
                            options: {
                                sourceMap: true,
                                importLoader: true,
                            }
                        }
                    ],
                    fallback: 'style-loader',
                }),
                exclude: /\.(eot|woff|woff2|ttf|svg)(\?[\s\S]+)?$/
            },
            {
                test: /\.(eot|woff|woff2|ttf|svg)(\?[\s\S]+)?$/,
                loader: 'url-loader?limit=1000&name=./fonts/[name].[ext]?[hash:base64:5]#icomoon',
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin({
            filename: 'bundle.css',
            allChunks: true,
        }),
        new webpack.DefinePlugin({
            "process.env": {
                BROWSER: JSON.stringify(true),
                NODE_ENV: JSON.stringify("production")
            }
        }),
    ],
    resolve: {
        extensions: ['.jsx', '.js', '.json']
    }
};

module.exports = config;




例如: server.build.js - > style__cont__2KTI-wF

bundle.js / bundle.css (客户端) - > style__cont__58B3ts_

我真的被困在这一点上,我很反应并且没有完美的方法来导入css服务器端。

0 个答案:

没有答案