【问题标题】:extracting css from scss file with webpack使用 webpack 从 scss 文件中提取 css
【发布时间】:2018-01-21 00:01:07
【问题描述】:

我正在尝试将 webpack 与我的 asp.net mvc 核心项目一起使用。我能够捆绑js文件。但我无法从 scss 文件中提取我的 css。

var path = require('path');
var extractTextPlugin = require("extract-text-webpack-plugin");
var cleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
    entry: {
        'role/role': './scripts/role/roleVM.ts',
        main: './scripts/main.ts',
        vendor: ["jquery"],
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'wwwroot/dist/js/')
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.scss$/,
                use: extractTextPlugin.extract({
                    use: [{
                        loader: "css-loader", options: {
                            sourceMap: true
                        }
                    }, {
                        loader: "sass-loader", options: {
                            sourceMap: true
                        }
                    }],
                    fallback: 'style-loader'
                }),
                exclude: /node_modules/,
            },
        ]
    },
    plugins: [
        new cleanWebpackPlugin(['dist'], {
            root: path.resolve(__dirname, 'wwwroot'),
            verbose: true,
            dry: false
        }),
        new extractTextPlugin("./css/main.css")
    ],
    resolve: {
        extensions: [".tsx", ".ts", ".js", '.scss']
    }
};

当我构建我的项目时,没有创建 css 文件

我的命令:

npm run build --color=always
> project@1.0.0 build C:\project\src\test
> webpack
clean-webpack-plugin: C:\project\src\project\wwwroot\dist has been removed.
ts-loader: Using typescript@2.4.2 and C:\project\src\project\tsconfig.json
Hash: 2cdaff8d8177eedec094
Version: webpack 3.5.3
Time: 2203ms
       Asset     Size  Chunks                    Chunk Names
role/role.js   293 kB       0  [emitted]  [big]  role/role
   vendor.js   271 kB       1  [emitted]  [big]  vendor
     main.js  2.48 kB       2  [emitted]         main
   [0] ./scripts/role/roleVM.ts 400 bytes {0} [built]
   [2] ./scripts/main.ts 0 bytes {2} [built]
   [3] multi jquery 28 bytes {1} [built]

看起来它跳过了通过提取文本插件。

我的配置文件有什么遗漏吗?

我目前的项目结构:

└── Project
    ├── wwwroot
    │   └── scss
    │     └── main.scss
    └── scripts
    │   └── main.ts
    │
    └── webpack.config.js

【问题讨论】:

  • 您是否在 main.ts 中导入了 .scss 文件?

标签: javascript css node.js npm webpack


【解决方案1】:

检查您是否在某处引用样式文件(将其导入 main.ts 等)。否则插件将无法工作,因为它找不到任何要提取的文件。

https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/354

【讨论】:

    猜你喜欢
    • 2017-06-04
    • 2017-06-09
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 2020-04-11
    • 2018-02-01
    • 2017-09-20
    • 1970-01-01
    相关资源
    最近更新 更多