SSR整合react-weui时报错!!!
来源:3-11 使用 Babel 处理 ES6 语法(1)
慕神0028795
2019-03-23
根据客户端和服务器端配置打包都没问题,但时执行 node ./dist/bundle.js
时报错。
1、webpack.server.js:
const path = require("path");
const nodeExternals = require("webpack-node-externals");
const merge = require("webpack-merge");
const config = require("./webpack.base.js");
const serverConfig = {
target: "node",
mode: "development",
entry: "./src/server/index.js",
output: {
filename: "bundle.js",
// path: path.resolve(__dirname, "../dist/server"),
publicPath: "/"
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.css?$/,
use: [
"isomorphic-style-loader",
{
loader: "css-loader",
options: {
modules: true
}
}
]
},
{
test: /\.(png|jpg|gif)$/,
use: {
loader: "url-loader",
options: {
name: path.posix.join("static", "img/[name]_[hash:6].[ext]"),
limit: 100
}
}
}
]
}
};
module.exports = merge(config, serverConfig);
2、代码中仅仅是引入了weui
import "weui";
3、bundle.js
/***/ "weui":
/*!***********************!*\
!*** external "weui" ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("module.exports = require(\"weui\");\n\n//# sourceURL=webpack:///external_%22weui%22?");
4、执行node ./dist/bundle.js
报错
C:\Users\Administrator\Desktop\demo\node_modules\_weui@1.1.3@weui\dist\style\weui.css:6
html{
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
写回答
2回答
-
脑阔疼
2019-04-04
看样子是没有识别出来你weui的css 也就可能 是css部分的loader出问题了 而引用外部包后出问题 考虑下是不是importloader参数需不需要 isomorphic-style-loader 看一下这个loader的配置吧
00 -
Dell
2019-04-02
同学你好,这是你业务中的代码问题吗
00
相似问题