开发者社区> 问答> 正文

电子+反应热装+打字稿+ SCSS导致热装失败

我已经设法让我的项目在热重装下运行,但后来我试图添加SCSS,现在当我在网络包中的所有东西的初始打包工作正常时,在我的电子应用程序中它说“热更新不成功”,我在控制台中得到以下错误:

./app/containers/App/App.scss 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> .h1 {
|   color: red;
| }

这是我的webpack.config.js

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

const env = process.env.NODE_ENV;

const appConfig = {
  mode: env || 'development',
  entry: ['./app/index'],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'renderer.bundle.js',
  },
  resolve: {
    modules: ['node_modules'],
    alias: {
      'react-dom': '@hot-loader/react-dom',
    },
    extensions: ['.ts', '.tsx', '.js', '.jsx'],
  },
  target: 'electron-renderer',
  module: {
    rules: [
      {
        test: /\.(j|t)s(x)?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            cacheDirectory: true,
            babelrc: false,
            presets: [
              ['@babel/preset-env', { targets: { browsers: 'last 1 version' } }],
              '@babel/preset-typescript',
              '@babel/preset-react',
            ],
            plugins: [
              // plugin-proposal-decorators is only needed if you're using experimental decorators in TypeScript
              ['@babel/plugin-proposal-decorators', { legacy: true }],
              ['@babel/plugin-proposal-class-properties', { loose: true }],
              'react-hot-loader/babel',
            ],
          },
        },
      },

      {
        test: /\.scss$/,
        include: /app/,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader", options: { modules: true } },
          { loader: "sass-loader" },
        ]
      },
    ],
  },
};

const mainConfig =   {
  mode: env || 'development',
  entry: './app/main.ts',
  target: 'electron-main',
  module: {
    rules: [{
      test: /\.ts$/,
      include: /app/,
      use: [{ loader: 'ts-loader' }]
    }]
  },
  output: {
    path: __dirname + '/dist',
    filename: 'main.js'
  }
};

const developmentConfig = {
  output: {
    publicPath: 'http://localhost:8080/',
  },
  plugins: [
    new ForkTsCheckerWebpackPlugin(),
    new webpack.NamedModulesPlugin()
  ],
  devtool: 'eval-source-map'
};

const productionConfig = {
  output: {
    publicPath: '/',
  },
};

module.exports = [mainConfig, merge(appConfig, env === 'production' ? productionConfig : developmentConfig)];

如果我在jsx中删除了对SCS的导入和引用,那么这个配置工作得很好。

这是我的软件包脚本部分js npm run watch 在
一个终端,然后我做了js npm start 一
会儿。

"scripts": {
    "watch": "rm -rf ./dist && mkdir ./dist && cp ./app/development.html ./dist/index.html && NODE_ENV=development webpack && NODE_ENV=development webpack-dev-server --hot",
    "build": "rm -rf ./dist && mkdir ./dist && cp ./app/production.html ./dist/index.html && NODE_ENV=development webpack",
    "start": "NODE_ENV=development electron ./dist/main.js"
  },

展开
收起
sossssss 2019-12-09 16:24:40 891 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《如何制作一个水平仪》 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载