首页 > 解决方案 > CSS 直接后代在生产构建中无法正常工作

问题描述

我怀疑这是 webpack 的问题,但我似乎无法让它工作。我唯一的 CSS 文件(main.css)包含以下代码:

.numpad > input {
    text-align: center;
    border: 2px solid blue;
    margin: auto;
}

但是,当我发布应用程序时,CSS 文件显示以下内容:

.numpad {
    text-align: center;
    border: 2px solid blue;
    margin: auto;
}
.numpad > input {
    text-align: center;
    border: 2px solid blue;
    margin: auto;
}

我已经在整个解决方案中搜索了可能导致第一个重复项的任何类型的重复项。它不存在。我的 webpack 配置如下:

module.exports = (env) => {
    const isDevBuild = !(env && env.prod);
    return [{
        stats: { modules: false },
        entry: { 'main': './ClientApp/boot.tsx' },
        resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
        output: {
            path: path.join(__dirname, bundleOutputDir),
            filename: '[name].js',
            publicPath: 'dist/'
        },
        devtool: 'inline-source-map',
        module: {
            rules: [
                { test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
                { test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
                { test: /\.js$/, include: /src/, exclude: /node_modules/, use: { loader: "babel-loader", options: { presets: ['env'] } } }
    ]
},

plugins: [
    new CheckerPlugin(),
    new webpack.DllReferencePlugin({
        context: __dirname,
        manifest: require('./wwwroot/dist/vendor-manifest.json')
    }),
    new CleanWebpackPlugin(['dist'])
].concat(isDevBuild ? [
    // Plugins that apply in development builds only
    new webpack.SourceMapDevToolPlugin({
        filename: '[file].map', // Remove this line if you prefer inline source maps
        moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
    })
] : [
        // Plugins that apply in production builds only
        new webpack.optimize.UglifyJsPlugin(),
        new ExtractTextPlugin('main.css')
    ])
}];
};

关于为什么要创建副本的任何想法?

标签: cssasp.net-corewebpack

解决方案


推荐阅读