我已经设法让我的项目在热重装下运行,但后来我试图添加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"
},
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。