天天看点

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

继续阅读