來(lái)來(lái)來(lái)代碼先上
十載的觀山湖網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷(xiāo)型網(wǎng)站的優(yōu)勢(shì)是能夠根據(jù)用戶(hù)設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整觀山湖建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)建站從事“觀山湖網(wǎng)站設(shè)計(jì)”,“觀山湖網(wǎng)站推廣”以來(lái),每個(gè)客戶(hù)項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
js/main.js
import * as aliasPerson from "./person.js"; import defaultPerson from "./person.js"; console.log("alias person is below ..."); console.log(aliasPerson); console.log(aliasPerson.prototype); console.log("default person is below ..."); console.log(defaultPerson); console.log(defaultPerson.prototype);
js/person.js
function Person(){} Person.nickname = "this is a person"; Person.birthday = "1900-01-01"; Person.prototype.eat = function(){}; module.exports = Person;
webpack.config.js
var entryFilePath = "./js/main.js"; var webpackConfig = { entry: entryFilePath, output: { filename: "result.js" }, module: { // rules: [{test: /\.js$/,loader: 'babel-loader'}] } }; module.exports = webpackConfig;
.babelrc
{ "presets": [ "es2015", "stage-3" ], "plugins": [ ["transform-runtime", { "helpers": false, "polyfill": false, "regenerator": true, "moduleName": "babel-runtime" }] ] }
package.json
{ "scripts": { "build": "webpack" }, "devDependencies": { "babel-core": "^6.26.3", "babel-loader": "^7.1.4", "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-3": "^6.24.1", "babel-runtime": "^6.26.0", "webpack": "^3.10.0", "webpack-dev-server": "^2.9.7" } }
一 不使用babel做轉(zhuǎn)義
直接執(zhí)行 npm run build 生成result.js
執(zhí)行 node result.js
import * as aliasPerson from "./person.js";
import defaultPerson from "./person.js";
執(zhí)行結(jié)構(gòu)完全一樣
二 使用babel做轉(zhuǎn)義
取消如下注釋.
執(zhí)行 npm run build 生成result.js
執(zhí)行 node result.js
使用 import * as aliasPerson from "./person.js";
多了 一個(gè)default屬性,并且 aliasPerson.prototype 為 undefined
原因如下
import * as aliasPerson from "./person.js";
當(dāng)引入的 ./person.js 模塊不為es 模塊的時(shí)候(obj.__esModule === false)
babel會(huì)將 module.exports 所指向的對(duì)象的非繼承屬性遍歷并附加到 newObj對(duì)象中,
并且 newObj.default = module.exports