我想把头缠住rollup。
我正在使用一个库来生成具有以下格式的文件:IIFE和require语句。例如
// index.js
(function() {
const myThing = require('./thing');
})()
//thing.js
module.exports = { a: 3 };
Run Code Online (Sandbox Code Playgroud)
我试图rollup与其他东西一起使用,但是我的bundle.js最终看起来像这样:
(function () {
var myThing = require('./thing');
})();
Run Code Online (Sandbox Code Playgroud)
我需要怎么做才能使bundle.js最终看起来像这样?:
(function () {
var myThing = { a: 3 };
})();
Run Code Online (Sandbox Code Playgroud)
万一我的设置有问题,这是rollup.config.js我正在使用的:
var babel = require('rollup-plugin-babel');
export default {
input: 'index.js',
output: {
file: 'dist/bundle.js',
format: 'es'
},
plugins: [
babel({
exclude: 'node_modules/**'
})
]
};
Run Code Online (Sandbox Code Playgroud)
这些是我已安装的软件包:
"babel-core": "^6.26.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",
"rollup": "^0.58.2",
"rollup-plugin-babel": "^3.0.4"
Run Code Online (Sandbox Code Playgroud)
而我的babel配置:
{
"presets": [
[
"env",
{
"modules": false
}
]
],
"plugins": [
"external-helpers"
]
}
Run Code Online (Sandbox Code Playgroud)
要构建,我只是在打电话rollup -c。
nac*_*cab 11
好吧,我想通了。我只需要使用 CommonJS 插件:
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
export default {
input: 'index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
plugins: [
resolve(),
commonjs(),
babel({
exclude: 'node_modules/**'
})
]
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2280 次 |
| 最近记录: |