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

 

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"]
    }
    ...
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章