我正在尝试从 node_modules 转译一个模块“react-device-detect”,但还无法实现。以下是我尝试过的:
module.exports = withLess({
webpack: (config, { isServer, defaultLoaders }) => {
// other configs
config.module.rules.push({
test: /\\.+(ts|tsx)$/,
include: [path.join(__dirname, 'node_modules/react-device-detect')],
// exclude: /node_modules/,
use: [{ loader: 'ts-loader' }],
});
config.module.rules.push({
test: /\\.+(js|jsx)$/,
include: [path.join(__dirname, 'node_modules/react-device-detect')],
// exclude: /node_modules/,
use: [{ loader: 'babel-loader' }],
});
return config;
},
});
Run Code Online (Sandbox Code Playgroud)
我也单独尝试过这些规则,但没有奏效。
更新 1: 完成 next.config.js 配置 @felixmosh
const webpack = require("webpack");
const withLess = require("@zeit/next-less");
const { parsed: localEnv } = require("dotenv").config();
require("dotenv").config({
path: process.env.NODE_ENV === "production" ? ".env.production" …Run Code Online (Sandbox Code Playgroud)