Last active
April 13, 2018 21:53
-
-
Save nmccready/6243c6ed0257a8e4db39672b8e029392 to your computer and use it in GitHub Desktop.
webpack es3 (for picky JS engines)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)) | |
} | |
} | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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()
asattemptVertx()
causes annoying auto breakpointing in google app scripts.