From 210947bc5997d206a6fa652ab0afaf2d5213f9d4 Mon Sep 17 00:00:00 2001 From: xcatliu Date: Tue, 29 Dec 2015 23:36:42 +0800 Subject: [PATCH] examples/hello-world works --- .babelrc | 2 +- examples/buildAll.js | 38 ------------------------------- examples/hello-world/entry.js | 22 ++++++++++++++---- examples/hello-world/package.json | 6 +++-- package.json | 9 ++++---- src/react-ie8.js | 6 ++--- 6 files changed, 30 insertions(+), 53 deletions(-) delete mode 100644 examples/buildAll.js diff --git a/.babelrc b/.babelrc index 9ceca208..c0e0fc29 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ { "presets": ["es2015", "stage-0"], "plugins": [ - "add-module-exports", + "transform-object-assign" ] } diff --git a/examples/buildAll.js b/examples/buildAll.js deleted file mode 100644 index da9b9f97..00000000 --- a/examples/buildAll.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Forked from https://github.com/rackt/redux/blob/master/examples/buildAll.js - * Runs an ordered set of commands within each of the build directories. - */ - -import fs from 'fs'; -import path from 'path'; -import { spawnSync } from 'child_process'; - -const exampleDirs = fs.readdirSync(__dirname).filter((file) => { - return fs.statSync(path.join(__dirname, file)).isDirectory(); -}); - -// Ordering is important here. `npm install` must come first. -const cmdArgs = [ - { cmd: 'npm', args: ['install'] }, - { cmd: 'npm', args: ['install', 'react-ie8@latest'] }, - { cmd: 'npm', args: ['run', 'build'] }, -]; - -for (const dir of exampleDirs) { - for (const cmdArg of cmdArgs) { - // declare opts in this scope to avoid https://github.com/joyent/node/issues/9158 - const opts = { - cwd: path.join(__dirname, dir), - stdio: 'inherit', - }; - let result = {}; - if (process.platform === 'win32') { - result = spawnSync(cmdArg.cmd + '.cmd', cmdArg.args, opts); - } else { - result = spawnSync(cmdArg.cmd, cmdArg.args, opts); - } - if (result.status !== 0) { - throw new Error('Building examples exited with non-zero'); - } - } -} diff --git a/examples/hello-world/entry.js b/examples/hello-world/entry.js index 0ebcabee..189f41de 100644 --- a/examples/hello-world/entry.js +++ b/examples/hello-world/entry.js @@ -1,8 +1,22 @@ -import reactIE8 from 'react-ie8'; -reactIE8(); +/** + * CANNOT use `import` to import `react-ie8`, + * because `import` will be transformed to `Object.defineProperty`, + * which doesn't exists in IE8 (but will be polyfilled after `require('react-ie8')()` executed). + */ +// import reactIE8 from 'react-ie8'; +// reactIE8(); -import React from 'react'; -import ReactDOM from 'react-dom'; +require('react-ie8')(); + +/** + * CANNOT use `import` to import `react` or `react-dom`, + * because `import` will run `react` before `require('react-ie8')()`. + */ +// import React from 'react'; +// import ReactDOM from 'react-dom'; + +const React = require('react'); +const ReactDOM = require('react-dom'); ReactDOM.render(

Hello World

, diff --git a/examples/hello-world/package.json b/examples/hello-world/package.json index 5e2e2ce8..fba60f04 100644 --- a/examples/hello-world/package.json +++ b/examples/hello-world/package.json @@ -4,7 +4,9 @@ "description": "React IE8 Hello World Example", "main": "entry.js", "scripts": { - "build": "webpack entry.js bundle.js", + "start": "npm run build && npm run serve", + "build": "npm i ../.. && webpack entry.js bundle.js", + "serve": "ecstatic --cache=false", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -27,7 +29,7 @@ "babel-preset-es2015": "^6.3.13", "babel-preset-react": "^6.3.13", "babel-preset-stage-0": "^6.3.13", - "es3ify-loader": "^0.1.0", + "ecstatic": "^1.4.0", "webpack": "^1.12.9" } } diff --git a/package.json b/package.json index 37e3bd14..a6afb9d6 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,6 @@ "build:lib": "babel src --out-dir lib", "build": "npm run build:lib", "prepublish": "npm run clean && npm run build", - "examples:build": "babel-node examples/buildAll.js", - "examples:serve-static": "ecstatic --cache=false examples", - "examples": "npm run examples:build && npm run examples:serve-static", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -30,11 +27,15 @@ "homepage": "https://github.com/xcatliu/react-ie8", "dependencies": { "console-polyfill": "^0.2.2", + "core-js": "^2.0.0", "es5-shim": "^4.4.1" }, "devDependencies": { + "babel": "^6.3.26", + "babel-cli": "^6.3.17", + "babel-core": "^6.3.26", "babel-eslint": "^5.0.0-beta6", - "babel-plugin-add-module-exports": "^0.1.2", + "babel-plugin-transform-object-assign": "^6.3.13", "babel-preset-es2015": "^6.3.13", "babel-preset-stage-0": "^6.3.13", "babelify": "^6.1.2", diff --git a/src/react-ie8.js b/src/react-ie8.js index 441a5f5d..ec85d815 100644 --- a/src/react-ie8.js +++ b/src/react-ie8.js @@ -12,11 +12,9 @@ const defaultOptions = { // 'font-face': false, }; -export default function reactIE8(options = {}) { +module.exports = function reactIE8(options = {}) { const finalOptions = Object.assign({}, defaultOptions, options); if (finalOptions['es5-shim']) require('es5-shim'); if (finalOptions['es5-sham']) require('es5-shim/es5-sham'); if (finalOptions['console-polyfill']) require('console-polyfill'); - // if (finalOptions['html5shiv']) require('html5shiv'); - // Object.keys(finalOptions).filter((key) => finalOptions[key]). -} +};