scraipt
Version:
Scrape away inefficient code during compile-time using AI
66 lines (65 loc) • 2.01 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const detectFramework = (config) => {
if (config.webpack && config.webpack.configure) {
return 'React';
}
if (config.entry || config.output) {
return 'webpack';
}
console.log(`${chalk_1.default.yellow('Warning:')} Could not detect framework. Defaulting to webpack.`);
// TODO: throw Error?
return 'webpack';
};
module.exports.useScraipt((config = {}, options = {}, framework) => {
if (!framework) {
framework = detectFramework(config);
}
if (framework === 'React') {
if (!config.webpack) {
config.webpack = {};
}
if (!config.webpack.configure) {
config.webpack.configure = {};
}
if (!config.webpack.configure.module) {
config.webpack.configure.module = {};
}
if (!config.webpack.configure.module.rules) {
config.webpack.configure.module.rules = [];
}
config.webpack.configure.module.rules.push({
test: /.[jt]sx*/,
use: [
{
loader: 'scraipt',
options: Object.assign({
// Default to include src folder only
include: ['src'] }, options),
},
],
});
}
else if (framework === 'webpack') {
if (!config.module) {
config.module = {};
}
if (!config.module.rules) {
config.module.rules = [];
}
config.module.rules.push({
test: /.[jt]sx*/,
use: [
{
loader: 'scraipt',
options,
},
],
});
}
return config;
});