我是使用Phoenix Framework进行React / redux / webpack的新手,并且试图从头开始设置新项目,并且遇到模块构建失败:SyntaxError:意外令牌
我已经尝试过回答类似问题,但是还无法解决。
这是错误:
未捕获的错误:模块解析失败:意外的令牌(14:0) 您可能需要适当的加载程序来处理此文件类型。 | | / *全局* /
&{@import“ semantic-ui-less / definitions / globals / reset”; } | &{@import“ semantic-ui-less / definitions / globals / site”; } |
webpack config.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']
}
});
app.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'))