Skip to content

Instantly share code, notes, and snippets.

@nmccready
Last active April 13, 2018 21:53
Show Gist options
  • Save nmccready/6243c6ed0257a8e4db39672b8e029392 to your computer and use it in GitHub Desktop.
Save nmccready/6243c6ed0257a8e4db39672b8e029392 to your computer and use it in GitHub Desktop.
webpack es3 (for picky JS engines)
const path = require('path');
// const UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); // for webpack 3 / 4.x
const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');
const GasPlugin = require('gas-webpack-plugin'); // for google-app-scripts
const { ProvidePlugin } = require('webpack');
const debug = require('./debug').spawn('webpack');
module.exports = {
entry: './index.js',
output: {
// libraryTarget: 'this',
path: path.resolve(__dirname, 'dist'),
filename: 'main.js' // webpack 2
// filename: 'main.min.js' // for webpack 3 /4 w UnminifiedWebpackPlugin
},
plugins: [
// new UnminifiedWebpackPlugin(),
// new ProvidePlugin({
// Promise: require('es6-promise/auto')
// }),
new GasPlugin(),
new ReplaceInFileWebpackPlugin([
{
dir: 'dist',
test: /\.js$/,
rules: [
// fix promise initialize for es6-promises to not throw errors in debugger
// this is to resolve GAppScript debugger hell (stops on all exceptions.. handled or not)
{
search: /if \(isNode\)(.|\n)*useSetTimeout\(\);\n.*\}/,
replace: 'scheduleFlush = useSetTimeout();'
}
]
}
])
],
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
// it should read babelrc.. but it is not!!
presets: ['env'],
plugins: [
'transform-object-assign',
'transform-class-properties',
'transform-object-rest-spread',
'lodash',
'transform-es3-member-expression-literals',
'transform-es3-property-literals'
].map(plug => require(`babel-plugin-${plug}`))
}
}
}
]
}
};
@nmccready
Copy link
Author

Not using transform-runtime and bluebird promises on purpose. They do not play well on google app scripts.

https://github.com/stefanpenner/es6-promise

Does seem to work.

For google I should add an Regex to search for https://github.com/stefanpenner/es6-promise/blob/90c0595230b2caa23eefdf9da3480322dbf4edf7/lib/es6-promise/asap.js#L109-L119

and force useSetTimeout() as attemptVertx() causes annoying auto breakpointing in google app scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment