Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

production build won't work next time #148

Closed
pro-wh opened this issue Oct 13, 2021 · 9 comments · Fixed by #171
Closed

production build won't work next time #148

pro-wh opened this issue Oct 13, 2021 · 9 comments · Fixed by #171
Labels
bug Something isn't working

Comments

@pro-wh
Copy link
Contributor

pro-wh commented Oct 13, 2021

we've just barely crossed over a threshold where a chunking rule (which it turned out we had in our webpack config) will start working. we don't load the resulting "common.js" file, so things will be broken.

ideas:

  • add common.js to places
  • disable that chunk splitting rule
  • ship a dev build 😆
@pro-wh pro-wh added the bug Something isn't working label Oct 13, 2021
@lukaw3d
Copy link
Member

lukaw3d commented Oct 13, 2021

I can't reproduce

  • Checked out master 09a81f6
  • yarn
  • yarn buildProd
  • Load into Chrome
  • Open popup
  • Check console for errors. No errors.

@pro-wh
Copy link
Contributor Author

pro-wh commented Oct 13, 2021

😱 did the i18n changes put us back under the limit?

@pro-wh
Copy link
Contributor Author

pro-wh commented Oct 13, 2021

oh right I forgot to mention that our partners and I were trying @oasisprotoco/client 0.1.0-alpha6

@pro-wh
Copy link
Contributor Author

pro-wh commented Oct 13, 2021

oh and additional info: I heard from bitcat that the rule is there because chrome will not load a file larger than 4 MB, so "disable that rule" is out

@lukaw3d
Copy link
Member

lukaw3d commented Oct 13, 2021

Whaat. Need proof

Unless all popups are ads https://blog.chromium.org/2020/05/resource-heavy-ads-in-chrome.html

@lvshaoping007
Copy link
Contributor

split is used for firefox . this is detail
mozilla/addons#662

@lvshaoping007
Copy link
Contributor

i add a file to fix after package .

@pro-wh
Copy link
Contributor Author

pro-wh commented Nov 12, 2021

@lvshaoping007 could you open a PR with that fix?

I'll read up on these webpack flags and see if I can fix it too, but it'd be convenient if you already have it fixed.

@pro-wh
Copy link
Contributor Author

pro-wh commented Dec 10, 2021

Let's go with #171.

An alternative, if we later need it, here's a script from shaoping that programmatically adds the common.js:

pkgBuild.js
var fs = require('fs');

const FILE_NAME = "common.js"
const EDIT_TYPE = {
    "DELETE": "DELETE",
    "ADD": "ADD"
}

let pathCommon = './dist/' + FILE_NAME;
let pathManifest = './dist/manifest.json';
let pathPopup = './dist/popup.html';


fs.readFile(pathCommon, function (err, data) {
    if (err) {
        checkManifest(EDIT_TYPE.DELETE)
        checkPopupHtml(EDIT_TYPE.DELETE)
    } else {
        checkManifest(EDIT_TYPE.ADD)
        checkPopupHtml(EDIT_TYPE.ADD)
    }
})

function checkPopupHtml(editType) {
    fs.readFile(pathPopup, function (err, data) {
        if(err){
            throw new Error("read popup.html failed , please check")
        }else{
            let scriptStr = data.toString();
            let fileIndex = scriptStr.indexOf(FILE_NAME)

            const START_STR = "<script"
            const END_STR = "</script>"
            const INSERT_STR = `<script src="./common.js"></script>\n`
            let scriptStartIndex = scriptStr.indexOf(START_STR)
            if (editType === EDIT_TYPE.ADD && fileIndex === -1) {
                let newStr = scriptStr.slice(0, scriptStartIndex) + INSERT_STR + scriptStr.slice(scriptStartIndex);
                updateFile(pathPopup, newStr)
            } else if (editType === EDIT_TYPE.DELETE && fileIndex !== -1) {
                let scriptEndIndex =  scriptStr.indexOf(END_STR,fileIndex) 
                let targetStr = scriptStr.slice(scriptStartIndex, scriptEndIndex+END_STR.length)
                let newStr = scriptStr.replace(targetStr,"")
                updateFile(pathPopup, newStr)
            }
        }
    })
}
function checkManifest(editType) {
    fs.readFile(pathManifest, function (err, data) {
        if (err) {
            throw new Error("read manifest.json failed , please check")
        } else {
            try {
                let scriptStr = data.toString();
                let scriptJson = JSON.parse(scriptStr)
                let scripts = scriptJson.background.scripts
                let fileIndex = scripts.indexOf(FILE_NAME)

                if (editType === EDIT_TYPE.ADD && fileIndex === -1) { 
                    scriptJson.background.scripts = [...scripts, FILE_NAME]
                    updateFile(pathManifest, JSON.stringify(scriptJson, "", "\t"))
                } else if (editType === EDIT_TYPE.DELETE && fileIndex !== -1) {
                    scripts.splice(fileIndex, 1);
                    scriptJson.background.scripts = scripts
                    updateFile(pathManifest, JSON.stringify(scriptJson, "", "\t"))
                }
            } catch (error) {
                console.log('checkManifest==error', error)
            }
        }
    })
}


function updateFile(path, data) {
    fs.writeFile(path, data, function (err) {
        if (err) {
            console.log(path + "update failed")
        } else {
            console.log(path + "update success");
        }
    })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants