reactjs - 模块解析失败,Webpack Phoenix React Semantic UI Theming 出现意外令牌
问题描述
我是使用 Phoenix 框架的 react/redux/webpack 的新手,我正在尝试从头开始设置一个新项目,但我遇到了 Module build failed: SyntaxError: Unexpected token
我已经尝试过类似问题的答案,但无法解决。
这是错误:
未捕获的错误:模块解析失败:意外令牌 (14:0) 您可能需要适当的加载程序来处理此文件类型。| | /* 全球的 */
& { @import "semantic-ui-less/definitions/globals/reset"; } | & { @import "semantic-ui-less/definitions/globals/site"; } |
webpack 配置.js
const webpack = require('webpack');
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (env, options) => ({
optimization: {
minimizer: [
new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }),
new OptimizeCSSAssetsPlugin({})
]
},
entry: {
'./js/app.js': ['./js/app.tsx']//.concat(glob.sync('./vendor/**/*.js'))
},
output: {
filename: 'app.js',
path: path.resolve(__dirname, '../priv/static/js')
},
module: {
rules: [
{
test: /\.(jsx?|tsx?)$/i,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.s?css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
// this rule handles images
{
test: /\.jpe?g$|\.gif$|\.ico$|\.png$|\.svg$/,
use: 'file-loader?name=[name].[ext]?[hash]'
},
// the following 3 rules handle font extraction
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
},
{
test: /\.otf(\?.*)?$/,
use: 'file-loader?name=/fonts/[name]. [ext]&mimetype=application/font-otf'
}
]
},
plugins: [
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
],
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
}
});
应用程序.tsx
import 'semantic-ui-less/semantic.less'
import "phoenix_html"
import * as React from 'react'
import * as ReactDOM from 'react-dom'
// Import local files
//
// Local files can be imported directly using relative paths, for example:
// import socket from "./socket"
import Root from './Root'
// This code starts up the React app when it runs in a browser. It sets up the routing
// configuration and injects the app into a DOM element.
ReactDOM.render(<Root />, document.getElementById('react-app'))
解决方案
推荐阅读
- asp.net-core - 我无法在 IIS 上发布 ASP.NET Core 3.0 项目
- reporting-services - SSRS 识别分组中的奇数行和偶数行
- sql - 选择 0 个值作为现有列名
- reactjs - 如何使用 Hook、createContext 和 GlobalState 包装器分离动作/reducers 逻辑?
- c++ - MinGW-w64 中的“get_s()”函数是什么
- java - UI 测试 - 断言排序数据 (Katalon/Selenium) Java
- c# - 测试自定义 JsonConverter 时出现异常
- java - Jboss(wildfly)中堆积的线程导致无响应
- javascript - 单选按钮处理程序中的代码似乎是错误的
- java - Intellij doExecute 未使用 DefaultProgramRunner 触发