UNPKG

next-with-linaria

Version:
82 lines 3.68 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addWebpackConfig = addWebpackConfig; const path_1 = __importDefault(require("path")); const consts_1 = require("./loaders/consts"); const webpack_utils_1 = require("./utils/webpack-utils"); function modifyCssLoaderConfig(rules) { for (const rule of rules) { if (!rule) continue; if ((0, webpack_utils_1.isCssLoader)(rule)) { if ((0, webpack_utils_1.isCssModule)(rule)) { const nextGetLocalIdent = rule.options.modules.getLocalIdent; const nextMode = rule.options.modules.mode; rule.options.modules.mode = (path) => { const isGlobal = consts_1.regexIsLinariaGlobalCSSQuery.test(path); if (isGlobal) { return 'local'; } return typeof nextMode === 'function' ? nextMode(path) : nextMode; }; rule.options.modules.getLocalIdent = (context, _, exportName, ...rest) => { if (consts_1.regexLinariaCSSQuery.test(context.resourceQuery)) { return exportName; } return nextGetLocalIdent(context, _, exportName, ...rest); }; } } if (typeof rule.use === 'object') { const useRules = rule.use; modifyCssLoaderConfig(Array.isArray(useRules) ? useRules : [useRules]); } if (Array.isArray(rule.oneOf)) { modifyCssLoaderConfig(rule.oneOf); } } } function addWebpackConfig(_a) { var { linaria = {} } = _a, nextConfig = __rest(_a, ["linaria"]); const webpack = (config, options) => { var _a; if (((_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) && config.plugins) { modifyCssLoaderConfig(config.module.rules); config.module.rules.push({ test: consts_1.regexLinariaCSS, loader: path_1.default.resolve(__dirname, './loaders/webpack-output-css-loader'), options: {}, exclude: /node_modules/, }); const linariaLoaderOptions = Object.assign({ sourceMap: process.env.NODE_ENV !== 'production', displayName: process.env.NODE_ENV !== 'production', babelOptions: { presets: ['next/babel', '@wyw-in-js'], } }, linaria); config.module.rules.push({ test: /\.(tsx|ts|js|mjs|jsx)$/, exclude: /node_modules/, loader: path_1.default.resolve(__dirname, './loaders/webpack-transform-loader'), options: linariaLoaderOptions, }); } if (typeof nextConfig.webpack === 'function') { return nextConfig.webpack(config, options); } return config; }; return Object.assign(Object.assign({}, nextConfig), { webpack }); } //# sourceMappingURL=add-webpack-config.js.map