javascript-obfuscator / javascript-obfuscator/webpack-obfuscator

Exclude files

未关闭
#166 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
928
派生
92
PR 合并指标
30 天内没有已合并 PR

描述

Hello all,

I have used webpack obfuscator previous version for webpack 4 with laravel mix. Now I have been trying this version and it works great, but when it tried to build the service worker always gives me an error saying that it cant find the self.__manifest. I realized that probably some files are being obfuscated and they should not. So, I decided to exclude the files that I was excluding before, but after trying some things, reading the docs and look to the webpackObfuscatorPlugin class and apply what it looks like its the correct way I am not being able to exclude the files I want.

This is the block of code that I am using:

if (mix.inProduction()) {
    /**
     * PWA code
     */
    mix.injectManifest({
        swSrc: './resources/js/service-worker.js',
        swDest: path.join(`${__dirname}/public`, 'service-worker.js'),
        mode: 'production',
    });

    mix.webpackConfig({
        plugins: [
            new WebpackObfuscator({
                    //rotateStringArray: true,
                    compact: true,
                    controlFlowFlattening: false,
                    deadCodeInjection: false,
                    debugProtection: false,
                    debugProtectionInterval: 0,
                    disableConsoleOutput: false,
                    identifierNamesGenerator: 'hexadecimal',
                    log: false,
                    numbersToExpressions: false,
                    renameGlobals: false,
                    selfDefending: false,
                    simplify: true,
                    splitStrings: false,
                    stringArray: true,
                    stringArrayCallsTransform: false,
                    stringArrayCallsTransformThreshold: 0.5,
                    stringArrayEncoding: [],
                    stringArrayIndexShift: true,
                    stringArrayRotate: true,
                    stringArrayShuffle: true,
                    stringArrayWrappersCount: 1,
                    stringArrayWrappersChainedCalls: true,
                    stringArrayWrappersParametersMaxCount: 2,
                    stringArrayWrappersType: 'variable',
                    stringArrayThreshold: 0.75,
                    unicodeEscapeSequence: false,
                },
                [
                    path.join(__dirname, 'node_modules'),
                    path.join(__dirname, 'resources/js/app.js'),
                    path.join(__dirname, 'resources/js/bootstrap.js'),
                    path.join(__dirname, 'resources/js/service-worker.js'),
                ]),
        ],
    });
}

Before this I do all the mix.js() to the files that I need for dev and production.

I am missing something important for sure, but can't find what I am doing wrong to exclude those files.

Maybe some mix function as it could be done in the old version?

mix.serve('php artisan lang:js')
    .obfuscator({
        options: {
            compact: true,
            controlFlowFlattening: false,
            deadCodeInjection: false,
            debugProtection: false,
            debugProtectionInterval: 0,
            disableConsoleOutput: false,
            identifierNamesGenerator: 'hexadecimal',
            log: false,
            numbersToExpressions: false,
            renameGlobals: false,
            selfDefending: false,
            simplify: true,
            splitStrings: false,
            stringArray: true,
            stringArrayCallsTransform: false,
            stringArrayCallsTransformThreshold: 0.5,
            stringArrayEncoding: [],
            stringArrayIndexShift: true,
            stringArrayRotate: true,
            stringArrayShuffle: true,
            stringArrayWrappersCount: 1,
            stringArrayWrappersChainedCalls: true,
            stringArrayWrappersParametersMaxCount: 2,
            stringArrayWrappersType: 'variable',
            stringArrayThreshold: 0.75,
            unicodeEscapeSequence: false
        },
        exclude: [
            path.resolve(__dirname, 'node_modules'),
            path.resolve(__dirname, 'resources/js/app.js'),
            path.resolve(__dirname, 'resources/js/bootstrap.js'),
            path.resolve(__dirname, 'resources/js/service-worker.js'),
        ]
    });
}

Thank you for the help :)

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先从 issue 中引用的 WebpackObfuscator 配置和 webpackObfuscatorPlugin 类开始,然后跟踪排除路径的匹配方式。复现涉及 resources/js/service-worker.js、app.js 和 bootstrap.js 的 Laravel Mix 生产构建。当列出的文件被排除,并且 service-worker 构建在没有 self.__manifest 错误的情况下完成时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript, webpack
领域
build-system, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。