1
我正在嘗試使用rollup.js:application.js
和dependencies.js
(分別包含我的應用程序代碼和公共庫代碼(react
,react-dom
等))創建2個單獨的版本。外部依賴關係錯誤地捆綁在rollup.js中?
文檔說我應該能夠簡單地使用externals: ['react', 'react-dom']
並使其工作 - 但是當我檢查所得到的包時,我仍然包含兩個庫的完整主體。這裏是我的例子app.config.js
,我打電話給我使用rollup -c app.config.js
:
我在做什麼錯?
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import nodeResolve from 'rollup-plugin-node-resolve'
import replace from 'rollup-plugin-replace'
import uglify from 'rollup-plugin-uglify'
import { keys } from 'lodash'
const PRODUCTION = (process.env.NODE_ENV || 'development') === 'production'
const ENVIRONMENT = JSON.stringify(PRODUCTION ? 'production' : 'development')
const EXTERNALS = {
'react': 'React',
'react-dom': 'ReactDOM',
}
const plugins = [
replace({ 'process.env.NODE_ENV': ENVIRONMENT }),
babel({
babelrc: false,
exclude: ['node_modules/**', '**/*.json'],
presets: ['es2015-rollup', 'react'],
}),
commonjs({
ignoreGlobal: false,
include: ['node_modules/**'],
}),
nodeResolve({
browser: true,
jsnext: true,
main: true,
preferBuiltins: false,
}),
]
if (PRODUCTION) {
plugins.push(uglify())
}
export default {
entry: 'source/application.js',
exports: 'none',
external: keys(EXTERNALS),
globals: EXTERNALS,
plugins,
targets: [{
dest: 'build/js/application.js',
format: 'iife',
sourceMap: !PRODUCTION,
sourceMapFile: '/js/application.js',
}],
treeshake: true,
}
嘗試使用webpack ..我發現它更容易 –