Joë*_*cht 4 javascript bundling-and-minification rollupjs
我正在尝试学习如何使用 rollup 来打包一些 javascript,遵循网上的一些教程。\n我一开始就坚持尝试使用配置文件。\n使用命令行一切似乎都正常,但使用配置文件它以语法错误结束Unexpected token 'export'。
我的配置是 Windows 11:
\nc:\\dev\\rollup-test>node --version\nv16.14.2\nc:\\dev\\rollup-test>rollup --version\nrollup v2.70.1\nRun Code Online (Sandbox Code Playgroud)\n配置文件:
\nc:\\dev\\rollup-test>type rollup.config.js\nexport default {\n input: './src/main.js',\n output: {\n file: './build/bundle.js',\n format: 'es'\n }\n };\nRun Code Online (Sandbox Code Playgroud)\nJavaScript 文件src\\main.js:
c:\\dev\\rollup-test>type src\\main.js\nconsole.log('hi there!');\nRun Code Online (Sandbox Code Playgroud)\n在 CLI 模式下,一切似乎都正常:
\nc:\\dev\\rollup-test>rollup ./src/main.js --file ./build/bundle.js --format es\n\n./src/main.js \xe2\x86\x92 ./build/bundle.js...\ncreated ./build/bundle.js in 29ms\nRun Code Online (Sandbox Code Playgroud)\n尝试使用上面的配置文件:
\nc:\\dev\\rollup-test>rollup --config\n[!] SyntaxError: Unexpected token 'export'\nc:\\dev.local\\rollup-test\\rollup.config.js:1\nexport default {\n^^^^^^\n\nSyntaxError: Unexpected token 'export'\n at Object.compileFunction (node:vm:352:18)\n at wrapSafe (node:internal/modules/cjs/loader:1032:15)\n at Module._compile (node:internal/modules/cjs/loader:1067:27)\n at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)\n at Object.require.extensions.<computed> [as .js] (C:\\Users\\joelh\\AppData\\Roaming\\npm\\node_modules\\rollup\\dist\\shared\\loadConfigFile.js:617:13)\n at Module.load (node:internal/modules/cjs/loader:981:32)\n at Function.Module._load (node:internal/modules/cjs/loader:822:12)\n at Module.require (node:internal/modules/cjs/loader:1005:19)\n at require (node:internal/modules/cjs/helpers:102:18)\n at loadConfigFromBundledFile (C:\\Users\\joelh\\AppData\\Roaming\\npm\\node_modules\\rollup\\dist\\shared\\loadConfigFile.js:622:42)\n\nc:\\dev\\rollup-test>\nRun Code Online (Sandbox Code Playgroud)\n可能有一些很明显的东西,但可惜我看不到它。\n任何人都可以帮助我走得更远吗?
\n小智 5
我有同样的问题。
解决方案是在 package.json 添加一行 "type": "module",
package.json
Run Code Online (Sandbox Code Playgroud)
package.json
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5954 次 |
| 最近记录: |