|
|
@ -6,6 +6,7 @@ const webpack = require('webpack'); |
|
|
|
const loaderUtils = require('loader-utils'); |
|
|
|
const loaderUtils = require('loader-utils'); |
|
|
|
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin'); |
|
|
|
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin'); |
|
|
|
const { WorkerLoaderName, FileNamePrefix } = require('./constants'); |
|
|
|
const { WorkerLoaderName, FileNamePrefix } = require('./constants'); |
|
|
|
|
|
|
|
const { resolve } = require('path'); |
|
|
|
|
|
|
|
|
|
|
|
// 正常 loader 处理逻辑
|
|
|
|
// 正常 loader 处理逻辑
|
|
|
|
function loader() { |
|
|
|
function loader() { |
|
|
@ -67,6 +68,22 @@ function loader() { |
|
|
|
entryOnly: true, |
|
|
|
entryOnly: true, |
|
|
|
}).apply(childCompiler); |
|
|
|
}).apply(childCompiler); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 去除源码中的less css引用
|
|
|
|
|
|
|
|
const regExp = /\.(css|less)$/; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin( |
|
|
|
|
|
|
|
regExp, |
|
|
|
|
|
|
|
result => { |
|
|
|
|
|
|
|
if (regExp.test(result.request)) { |
|
|
|
|
|
|
|
result.request = resolve(__dirname, './empty.js'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (regExp.test(result.resource)) { |
|
|
|
|
|
|
|
result.resource = resolve(__dirname, './empty.js'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
).apply(childCompiler); |
|
|
|
|
|
|
|
|
|
|
|
const subCache = `subcache ${__dirname} ${workerEntry}`; |
|
|
|
const subCache = `subcache ${__dirname} ${workerEntry}`; |
|
|
|
childCompiler.hooks.compilation.tap(WorkerLoaderName, compilation => { |
|
|
|
childCompiler.hooks.compilation.tap(WorkerLoaderName, compilation => { |
|
|
|
if (compilation.cache) { |
|
|
|
if (compilation.cache) { |
|
|
@ -98,16 +115,18 @@ function loader() { |
|
|
|
null, |
|
|
|
null, |
|
|
|
// 插入代码的转译和压缩由主构建配置的 babel/ts loader 处理, 不需要 worker-worker 来处理
|
|
|
|
// 插入代码的转译和压缩由主构建配置的 babel/ts loader 处理, 不需要 worker-worker 来处理
|
|
|
|
// 添加 @ts-nocheck 避免 ts-check 报错
|
|
|
|
// 添加 @ts-nocheck 避免 ts-check 报错
|
|
|
|
|
|
|
|
// 修复export const 下 const不会被转译的问题
|
|
|
|
`// @ts-nocheck
|
|
|
|
`// @ts-nocheck
|
|
|
|
const blob = new Blob([${JSON.stringify(compilation.assets[entry].source())}]); |
|
|
|
const blob = new Blob([${JSON.stringify(compilation.assets[entry].source())}]); |
|
|
|
export const workerUrl = window.URL.createObjectURL(blob); |
|
|
|
const workerUrl = window.URL.createObjectURL(blob); |
|
|
|
|
|
|
|
export default workerUrl; |
|
|
|
` |
|
|
|
` |
|
|
|
) |
|
|
|
) |
|
|
|
: callback( |
|
|
|
: callback( |
|
|
|
null, |
|
|
|
null, |
|
|
|
`// @ts-nocheck
|
|
|
|
`// @ts-nocheck
|
|
|
|
const servicePath = __webpack_public_path__ + ${JSON.stringify(entry)}; |
|
|
|
const servicePath = __webpack_public_path__ + ${JSON.stringify(entry)}; |
|
|
|
export const workerUrl = servicePath; |
|
|
|
export default servicePath; |
|
|
|
` |
|
|
|
` |
|
|
|
) |
|
|
|
) |
|
|
|
}); |
|
|
|
}); |
|
|
|