1

我正在尝试配置 webpack 以将 scss 文件编译到 /dist/css 文件夹中。我不想将 css 与 js 捆绑在一起。但我遇到了一个错误。

我究竟做错了什么?

我尝试重新安装 webpack 和 npm rebuild node-sass 但它对我不起作用。

我实际的 webpack.config.js:

const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
    entry: {
        main: './src/main.ts',
        inject: './src/inject.ts',
        popup: ['./src/popup.ts', './styles/popup.scss'],
        content: './src/content.ts'
    },
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            },
            {
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'sass-loader',
                    'css-loader'
                ]
            }
        ]
    },
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: "./dist/css/[name].css",
            chunkFilename: "./dist/css/[id].css"
        })
    ]
};

错误输出:

ERROR in ./styles/popup.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):

html,body {
^
      Invalid CSS after "e": expected 1 selector or at-rule, was "exports = module.ex"
      in project\styles\popup.scss (line 1, column 1)
    at runLoaders (project\node_modules\webpack\lib\NormalModule.js:301:20)
    at project\node_modules\loader-runner\lib\LoaderRunner.js:367:11
    at project\node_modules\loader-runner\lib\LoaderRunner.js:233:18
    at context.callback (project\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at Object.render [as callback] (project\node_modules\sass-loader\lib\loader.js:52:13)
    at Object.done [as callback] (project\node_modules\neo-async\async.js:8077:18)
    at options.error (project\node_modules\node-sass\lib\index.js:294:32)
 @ multi ./src/popup.ts ./styles/popup.scss popup[1]
Child mini-css-extract-plugin node_modules/sass-loader/lib/loader.js!node_modules/css-loader/dist/cjs.js!styles/popup.scss:
    Entrypoint mini-css-extract-plugin = *
    [0] ./node_modules/sass-loader/lib/loader.js!./node_modules/css-loader/dist/cjs.js!./styles/popup.scss 290 bytes {0} [built] [failed] [1 error]

    ERROR in ./styles/popup.scss (./node_modules/sass-loader/lib/loader.js!./node_modules/css-loader/dist/cjs.js!./styles/popup.scss)
    Module build failed (from ./node_modules/sass-loader/lib/loader.js):

    html,body {
    ^
          Invalid CSS after "e": expected 1 selector or at-rule, was "exports = module.ex"
          in project\styles\popup.scss (line 1, column 1)
4

0 回答 0