ko
Version:
build & lint library
112 lines (111 loc) • 4.39 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const babel_1 = __importDefault(require("./babel"));
class Script {
constructor(opts) {
this.THREAD_LOADER = require.resolve('thread-loader');
this.WORKER_LOADER = require.resolve('worker-loader');
this.ESBUILD_LOADER = require.resolve('esbuild-loader');
this.opts = opts;
this.BABEL_LOADER = new babel_1.default(opts);
}
get config() {
const scriptLoader = [
{
test: /\.worker.[jt]s$/,
loader: this.WORKER_LOADER,
include: (input) => /dt-react-monaco-editor[\\/]lib[\\/]languages/.test(input),
options: {
inline: 'fallback',
},
},
// Monaco worker 依赖专用规则(注入 corejs 兼容 chrome 66)
{
test: /\.m?(t|j)sx?$/,
include: (input) => {
return (input.includes('monaco-sql-languages') ||
input.includes('dt-sql-parser') ||
input.includes('antlr4ng') ||
input.includes('antlr4-c3'));
},
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [
[
require.resolve('@babel/preset-env'),
{
useBuiltIns: 'usage',
corejs: 3,
targets: 'chrome >= 66',
},
],
[require.resolve('@babel/preset-typescript')],
],
babelrc: false,
configFile: false,
cacheDirectory: true,
cacheCompression: false,
},
},
],
},
{
test: /\.m?(t|j)sx?$/,
include: (input) => {
if (input.includes('monaco-sql-languages') ||
input.includes('dt-sql-parser') ||
input.includes('antlr4ng') ||
input.includes('antlr4-c3')) {
return false;
}
// internal modules dt-common compatible
if (/node_modules[\\/]dt-common[\\/]src[\\/]/.test(input)) {
return true;
}
else if (input.includes('immer')) {
return true;
}
else if (input.includes('react-grid-layout')) {
return true;
}
else if (input.includes('monaco-editor')) {
return true;
}
if (this.opts.babelIncludes?.some(item => item && input.includes(item))) {
return true;
}
if (input.includes('node_modules')) {
return false;
}
else {
return true;
}
},
use: [
{
loader: this.THREAD_LOADER,
options: {
name: 'ko-js-pool',
},
},
this.opts.experiment?.speedUp
? {
loader: this.ESBUILD_LOADER,
options: {
loader: 'tsx',
target: 'es2015',
},
}
: this.BABEL_LOADER.config,
].filter(Boolean),
},
];
return scriptLoader;
}
}
exports.default = Script;