我正在尝试为使用SSR构建的React组件添加CSS,但是我无法做到。 我查看了以下内容:
- https://www.npmjs.com/package/isomorphic-style-loader
- https://cssinjs.org/server-side-rendering/?v=v10.0.0-alpha.22
- webpack加载器
这是我的样板包 - https://github.com/alexnm/react-ssr 如何将样式添加到我的React SSR代码中。 更新Unexpected token (1:0) You may need an appropriate loader to handle this file type.
const dev = process.env.NODE_ENV !== "production";
const path = require( "path" );
const { BundleAnalyzerPlugin } = require( "webpack-bundle-analyzer" );
const FriendlyErrorsWebpackPlugin = require( "friendly-errors-webpack-plugin" );
const plugins = [
new FriendlyErrorsWebpackPlugin(),
];
if ( !dev ) {
plugins.push( new BundleAnalyzerPlugin( {
analyzerMode: "static",
reportFilename: "webpack-report.html",
openAnalyzer: false,
} ) );
}
module.exports = {
mode: dev ? "development" : "production",
context: path.join( __dirname, "src" ),
devtool: dev ? "none" : "source-map",
entry: {
app: "./client.js",
},
resolve: {
modules: [
path.resolve( "./src" ),
"node_modules",
],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
},
],
},
output: {
path: path.resolve( __dirname, "dist" ),
filename: "[name].bundle.js",
},
plugins,
};