3

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

实用程序/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 中遇到了这个错误: Uncaught ReferenceError: global is not defined(...)

我的汇总配置

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
        }
    };
};
4

0 回答 0