天天看點

ionic4&angular8使用指令ionic build --prod打包之後本地輕按兩下www/index.html浏覽器無法通路,必須把www部署到web伺服器上才能正常通路。

ionic4&angular8+打包之後本地輕按兩下通路www/index.html空白報錯,隻有把www部署到web伺服器上才能正常通路。經過反複查閱資料,對比ionic3和ionic4工程配置(tsconfig.json)才發現,原來是使用了:ES6子產品!

報錯資訊:

Access to script at 'file:///C:/Users/Administrator/Desktop/www/runtime-es2015.847c257376eede5504e2.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

runtime-es2015.847c257376eede5504e2.js:1 Failed to load resource: net::ERR_FAILED

ionic4&angular8使用指令ionic build --prod打包之後本地輕按兩下www/index.html浏覽器無法通路,必須把www部署到web伺服器上才能正常通路。

TypeScript 編譯選項:

https://www.tslang.cn/docs/handbook/compiler-options.html

tsconfig.json 配置對比:

//ionic3 tsconfig.json 

{
    "compilerOptions": {
        "module": "es2015",
        "target": "es5",
        "lib": ["dom", "es2015"]
    }
    ...
}


//ionic4 tsconfig.json 

{
    "compileOnSave": false,
    "compilerOptions": {
        "module": "esnext",
        "target": "es2015",
        "lib": ["es2018", "dom"]
    }
    ...
}
           

繼續閱讀