SHARE
TWEET

Untitled

a guest Feb 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const babel = require('@babel/core');
  2.  
  3. const _global = global || window;
  4. _global.transform = function(code, cb) {
  5.   babel.transform(code, {
  6.     minified: true,
  7.     presets: ['@babel/preset-env'],
  8.   }, (err, result) => {
  9.     if (err)cb(err, null);
  10.     else cb(null, result.code);
  11.   });
  12. };
  13.    
  14. const path = require('path');
  15.  
  16. module.exports = {
  17.   entry: './src/index.js',
  18.   mode: 'production',
  19.   output: {
  20.     path: path.resolve(__dirname, 'dist'),
  21.   },
  22.   module: {
  23.     rules: [
  24.       {
  25.         test: /.js$/,
  26.         include: [
  27.           path.resolve(__dirname, "node_modules/@babel/core"),
  28.           path.resolve(__dirname, "node_modules/@babel/preset-env")
  29.         ],
  30.         use: {
  31.           loader: 'babel-loader',
  32.           options: {
  33.             presets: ['@babel/preset-env'],
  34.           },
  35.         },
  36.       },
  37.     ],
  38.   },
  39.   target: 'node'
  40. };
  41.    
  42. { Error: Cannot find module '/Users/〇〇/Projects/webpack-demo/node_modules/@babel/preset-env/lib/index.js'
  43. at n (/Users/〇〇/Projects/webpack-demo/dist/main.js:42:100955)
  44. at b (/Users/〇〇/Projects/webpack-demo/dist/main.js:1750:55188)
  45. at t.loadPreset (/Users/〇〇/Projects/webpack-demo/dist/main.js:1750:53373)
  46. at m (/Users/〇〇/Projects/webpack-demo/dist/main.js:42:104613)
  47. at /Users/〇〇/Projects/webpack-demo/dist/main.js:42:103548
  48. at Array.map (<anonymous>)
  49. at R (/Users/〇〇/Projects/webpack-demo/dist/main.js:42:103523)
  50. at g (/Users/〇〇/Projects/webpack-demo/dist/main.js:42:103430)
  51. at /Users/〇〇/Projects/webpack-demo/dist/main.js:42:102661
  52. at /Users/〇〇/Projects/webpack-demo/dist/main.js:1:122682 code: 'MODULE_NOT_FOUND' }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top