汇总js配置 - 全局?

时间:2016-11-11 09:35:25

标签: reactjs webpack babeljs commonjs rollupjs

我有一个用webpack编译的项目,一切运行良好,但我们正在转向rollupJS,我被导入的文件所困。

utils的/ INIT-jquery.jsx

global.$ = global.jQuery = require('jquery');
require('jquery-mask-plugin');
require('fancybox')(global.$);
require('libraries/jquery.unserialize');

此文件已导入,例如此文件 app.jsx

import React from 'react';
import { render } from 'react-dom';

import InitJquery from 'common/utils/init-jquery';
import Init from 'common/utils/init';

...

我在控制台chrome中遇到了这个错误: 未捕获的ReferenceError:未定义全局(...)

我的汇总配置

var multiEntry = require('rollup-plugin-multi-entry');
var babel = require('rollup-plugin-babel');
var uglify = require('rollup-plugin-uglify');
var rollupIncludePaths = require('rollup-plugin-includepaths');

var nodeResolve = require( 'rollup-plugin-node-resolve');
var commonjs = require( 'rollup-plugin-commonjs');
var replace = require( 'rollup-plugin-replace');

const includePathOptions = {  
    paths: ['target/scripts'],
    extensions: ['.jsx','.js']
};

var cache;

module.exports = function(grunt) {
    return {
        options: {        
            plugins: function () {
                return [
                    rollupIncludePaths(includePathOptions),
                    replace({
                        'process.env.NODE_ENV': JSON.stringify( 'production' )
                    }),
                    nodeResolve({ jsnext: true, main: true }),
                    commonjs({
                       // extensions: [ '.js' ],
                        sourceMap: true,
                        //include: 'target/scripts/common/utils',
                        //ignoreGlobal: true,
                        namedExports: {
                            // left-hand side can be an absolute path, a path
                            // relative to the current directory, or the name
                            // of a module in node_modules
                            'formsy-react': [ 'Form', 'Mixin' ],
                            'react-dom': [ 'render' ],
                            'react': [ 'Component' ]
                        }
                    }),
                    babel({
                        babelrc: false,
                        presets: [["es2015",{modules:false}], "react"],
                        exclude: ['*/__tests__/**/*', './node_modules/**/*'],
                        plugins: ["external-helpers"]
                    }),
                    uglify()      
                ];
            },

            cache:cache,
            sourceMap: true,
            format: 'cjs',
        },
        main: {
            dest: './target/scripts/checkout/cart.bundle.js',
            src: './target/scripts/checkout/cart/app-cart.jsx', // Only one source file is permitted
        }
    };
};

0 个答案:

没有答案