Closed wind0204 closed 4 years ago
Here's the content of the file 'rollup.config.js':
// const replace = require('rollup-plugin-replace');
import { terser } from 'rollup-plugin-terser';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
// `npm run build` -> `production` is true
// `npm run dev` -> `production` is false
const production = !process.env.ROLLUP_WATCH;
export default {
input: ['src/main.js', 'src/chat.js'],
output: [
{
dir: 'public/js',
format: 'es',
//format: 'iife', // immediately-invoked function expression — suitable for <script> tags
sourcemap: production ? false : true
}, /* {
file: 'public/js/bundle-system.js',
format: 'system',
//format: 'iife', // immediately-invoked function expression — suitable for <script> tags
sourcemap: production && false
}, */
],
moduleContext: {
'node_modules/jquery/dist/jquery.slim.min.js': 'window',
'node_modules/handlebars/dist/handlebars.min.js': 'window',
},
plugins: [
// replace({
// 'process.env.NODE_ENV': JSON.stringify('production')
// }),
resolve({
// the fields to scan in a package.json to determine the entry point
// if this list contains "browser", overrides specified in "pkg.browser"
// will be used
//mainFields: ['module', 'main'], // Default: ['module', 'main']
// DEPRECATED: use "mainFields" instead
// use "module" field for ES6 module if possible
//module: true, // Default: true
// DEPRECATED: use "mainFields" instead
// use "jsnext:main" if possible
// legacy field pointing to ES6 module in third-party libraries,
// deprecated in favor of "pkg.module":
// - see: https://github.com/rollup/rollup/wiki/pkg.module
//jsnext: true, // Default: false
// DEPRECATED: use "mainFields" instead
// use "main" field or index.js, even if it's not an ES6 module
// (needs to be converted from CommonJS to ES6)
// – see https://github.com/rollup/rollup-plugin-commonjs
//main: true, // Default: true
// some package.json files have a "browser" field which specifies
// alternative files to load for people bundling for the browser. If
// that's you, either use this option or add "browser" to the
// "mainfields" option, otherwise pkg.browser will be ignored
//browser: true, // Default: false
// not all files you want to resolve are .js files
//extensions: [ '.mjs', '.js', '.jsx', '.json' ], // Default: [ '.mjs', '.js', '.json', '.node' ]
// whether to prefer built-in modules (e.g. `fs`, `path`) or
// local ones with the same names
preferBuiltins: false, // Default: true
// Lock the module search in this path (like a chroot). Module defined
// outside this path will be marked as external
//jail: '/my/jail/path', // Default: '/'
// Set to an array of strings and/or regexps to lock the module search
// to modules that match at least one entry. Modules not matching any
// entry will be marked as external
//only: [ 'some_module', /^@some_scope\/.*$/ ], // Default: null
// If true, inspect resolved files to check that they are
// ES2015 modules
//modulesOnly: true, // Default: false
// Force resolving for these modules to root's node_modules that helps
// to prevent bundling the same package multiple times if package is
// imported from dependencies.
//dedupe: [ 'react', 'react-dom' ], // Default: []
// Any additional options that should be passed through
// to node-resolve
//customResolveOptions: {
// moduleDirectory: 'js_modules'
//}
}),
commonjs({
// non-CommonJS modules will be ignored, but you can also
// specifically include/exclude files
//include: 'node_modules/**', // Default: undefined
include: [
'node_modules/buffer/**',
'node_modules/long/**',
], // Default: undefined
//exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ], // Default: undefined
// these values can also be regular expressions
// include: /node_modules/
// search for files other than .js files (must already
// be transpiled by a previous plugin!)
//extensions: [ '.js', '.coffee' ], // Default: [ '.js' ]
// if true then uses of `global` won't be dealt with by this plugin
//ignoreGlobal: false, // Default: false
// if false then skip sourceMap generation for CommonJS modules
sourceMap: production ? false : true, // Default: true
// explicitly specify unresolvable named exports
// (see below for more details)
//namedExports: { './module.js': ['foo', 'bar' ] }, // Default: undefined
// sometimes you have to leave require statements
// unconverted. Pass an array containing the IDs
// or a `id => boolean` function. Only use this
// option if you know what you're doing!
//ignore: [ 'conditional-runtime-dependency' ],
}),
production && terser(), // minify, but only in production
]
};
Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid.
We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets reopened and transferred to the new repo. :beer:
I'm new to javascript stuff and have been learning them by making a simple web app interface; and just ran into a problem that I couldn't solve with my beginner's luck :)
One js file I wrote which had a dependency that in turn has two CommonJS dependencies was rolled up into a buggy bundle.
The console in my browser says "Uncaught (in promise) ReferenceError: exports is not defined at chat.js:1333".
I'm sharing my code hoping someone can find out what is the problem and assist me. I would be very sorry if it was just a silly mistake on my part.
the chat.js made by rollup (without minification): https://www.dropbox.com/s/d2hh2ft8iolfbpj/chat.js?dl=0 the project: https://www.dropbox.com/s/20xa0dfyh9ra6jc/webapp.tar.xz?dl=0
So, the problem will pop up when you click "About" element, as soon as you click it and the page loads, it'll load js/chat.js, then the error will occur.
Thank you.