https://github.com/stereobooster/main-module-browser-test
Experiment
https://github.com/stereobooster/main-module-browser-test
Last synced: 3 months ago
JSON representation
Experiment
- Host: GitHub
- URL: https://github.com/stereobooster/main-module-browser-test
- Owner: stereobooster
- Created: 2018-01-07T21:16:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-07T22:54:26.000Z (almost 8 years ago)
- Last Synced: 2025-04-19T10:54:25.874Z (8 months ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Experiment
discussion happens here https://github.com/stereobooster/package.json/issues/2
```sh
yarn
# node
node src/index.js
CommonJS
node --experimental-modules src/index.esm.js
SyntaxError: Unexpected token import
node --experimental-modules src/index.mjs
(node:21541) ExperimentalWarning: The ESM module loader is experimental.
CommonJS
# webpack
npx webpack src/index.js build/main.js --target web
node build/main.js
{ default: 'ES module browser' }
npx webpack src/index.esm.js build/main.js --target web
node build/main.js
ES module browser
npx webpack src/index.js build/main.js --target node
node build/main.js
{ default: 'ES module' }
npx webpack src/index.esm.js build/main.js --target node
node build/main.js
ES module
# @std/esm
node -r @std/esm src/index.mjs
CommonJS
node -r @std/esm src/index.esm.js
SyntaxError: 'import' and 'export' may only be used in ES modules
# with "@std/esm": { "esm": "js" } in package.json
node -r @std/esm src/index.js
CommonJS
node -r @std/esm src/index.esm.js
CommonJS
# with "@std/esm": { "esm": "all" } in package.json
node -r @std/esm src/index.js
ReferenceError: require is not defined
node -r @std/esm src/index.esm.js
CommonJS
```
structure of `package.json`
```json
{
"name": "main-module-browser",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"browser": {
"./dist/index.js": "./dist/index.browser.js",
"./dist/index.esm.js": "./dist/index.browser.esm.js"
}
}
```
[List of targets](https://webpack.js.org/configuration/target/).