Beispiel #1
0
function dev(name: string, callback: () => void) {
  //var filename = name.split('/')[1].substr(0, 3) + '-' + name.split('/')[1].substr(3) + '.js'
  var filename = _.kebabCase(name.split('/')[1]) + '.js'
  var options: any = {
    entry: './' + name + '.js',
    output: {
      path: path.join(__dirname, '../../../public/assets/js'),
      publicPath: "/assets/",
      filename: "bundle.js"
    },
    resolve: {
      extensions: ['', '.webpack.js', '.web.js', '.js']
    },
    module: {
      loaders: [
        { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
        { test: /\.less$/, exclude: /node_modules/, loader: 'style!css!less' }
      ]
    },
    devtool: "sourcemap",
    debug: true
  }
  var port = 7070

  var compiler = webpack(options)
  return new WebpackDevServer(compiler, {
    stats: {
      colors: true
    },
    historyApiFallback: true
  }).listen(port, "localhost", function(err) {
    if (err) throw err
    callback()
  })
}
Beispiel #2
0
export async function webpackDevServer(): Promise<void> {
    const compiler = createWebpackCompiler(webpackConfig)
    const server = new WebpackDevServer(compiler as any, {
        publicPath: '/.assets/',
        contentBase: './ui/assets',
        stats: WEBPACK_STATS_OPTIONS,
        noInfo: false,
        proxy: {
            '/': {
                target: 'http://localhost:3081',
                ws: true,
                // Avoid crashing on "read ECONNRESET".
                onError: err => console.error(err),
                onProxyReqWs: (_proxyReq, _req, socket) =>
                    socket.on('error', err => console.error('WebSocket proxy error:', err)),
            },
        },
    })
    return new Promise<void>((resolve, reject) => {
        server.listen(3080, '127.0.0.1', (err?: Error) => {
            if (err) {
                reject(err)
            } else {
                resolve()
            }
        })
    })
}
  run: function(runTaskOptions: ServeTaskOptions) {

    var project = this.cliProject;

    rimraf.sync(path.resolve(project.root, runTaskOptions.outputPath));

    const config = new NgCliWebpackConfig(project, runTaskOptions.environment).config;
    const webpackCompiler = webpack(config);

    webpackCompiler.apply(new ProgressPlugin({
      profile: true
    }));

    return new Promise( (resolve, reject) => {
      webpackCompiler.watch({}, (err, stats) => {
        if (err) {
          lastHash = null;
          console.error(err.stack || err);
          if(err.details) console.error(err.details);
            reject(err.details);
        }

        if(stats.hash !== lastHash) {
          lastHash = stats.hash;
          process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
        }
      })
    })
  }
    it('bundleable by webpack with no errors', async function() {
        this.timeout(50000);
        const memoryFS = new MemoryFS();
        const rootPath = await pkgDir(__dirname);

        const compiler = webpack({
            mode: 'development',
            entry: {
                main: path.join(rootPath!, 'dist', 'src', 'lib', 'service.js')
            },
            node: {
                path: 'empty', // users should provide alias to path-webpack
                net: 'empty',
                fs: 'empty',
                module: 'empty'
            }
        });

        compiler.outputFileSystem = memoryFS;

        await new Promise((res, rej) =>
            compiler.run((err, stats) => {
                if (err || stats.hasErrors()) {
                    rej(err || new Error(stats.toString()));
                } else {
                    res();
                }
            })
        );
    });
Beispiel #5
0
 private compiler(): Property<webpack.Compiler, Error> {
   try {
     return Kefir.constant(webpack(this.config));
   } catch (e) {
     return Kefir.constantError(e);
   }
 }
  run: function(runTaskOptions: ServeTaskOptions) {

    var project = this.cliProject;

    rimraf.sync(path.resolve(project.root, runTaskOptions.outputPath));
    var config = new NgCliWebpackConfig(project, runTaskOptions.environment).config;
    const webpackCompiler = webpack(config);

    const ProgressPlugin  = require('webpack/lib/ProgressPlugin');

    webpackCompiler.apply(new ProgressPlugin({
      profile: true
    }));

    return new Promise((resolve, reject) => {
      webpackCompiler.run((err, stats) => {
        // Don't keep cache
        // TODO: Make conditional if using --watch
        webpackCompiler.purgeInputFileSystem();

        if(err) {
          lastHash = null;
          console.error(err.stack || err);
          if(err.details) console.error(err.details);
            reject(err.details);
        }

        if(stats.hash !== lastHash) {
          lastHash = stats.hash;
          process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
        }
        resolve();
      });
    });
  }
Beispiel #7
0
export const bundle = (entry: any, output: string, tsconfig?: string, outputDir?: string, watch?: boolean, minify?: boolean, callback?: any) => {
  const webpackConfig = Object.assign<{[index: string]: any}, typeof config>({}, config)
  const plugins = []
  if (minify) {
    plugins.push(new webpack.optimize.UglifyJsPlugin({
      mangle: {
        except: ['$super', '$', 'exports', 'require']
      },
      compress: {
        warnings: false
      }
    }))
    delete webpackConfig.devtool
  }
  if (tsconfig) {
    webpackConfig.ts.configFileName = tsconfig
  }
  webpackConfig.entry = entry
  webpackConfig.plugins = plugins
  webpackConfig.output.path = path.join(process.cwd(), outputDir || 'dist')
  webpackConfig.output.filename = output
  webpackConfig.watch = watch
  return webpack(webpackConfig, (err, stats) => {
    if (err) {
      throw new gutil.PluginError('webpack', err)
    }
    gutil.log('[webpack]', stats.toString())
    callback()
  })
}
export function startPublications() {
  const mode = process.env.NODE_ENV || "DEVELOPMENT";
  const app = express();

  if (mode.toUpperCase() === "DEVELOPMENT") {
    const compiler = webpack(webpackConfig as webpack.Configuration);
    app.use(
      webpackDevMiddleware(compiler, {
        publicPath: webpackConfig.output.publicPath,
      })
    );
    app.use(webpackHotMiddleware(compiler));
    app.use("/playground", graphqlPlayground({ endpoint: "/graphql" }));
  } else {
    const publicPath = path.resolve(__dirname, "../public");
    app.use(express.static(publicPath));
    app.get("*", (req, res) =>
      res.sendFile(path.resolve(publicPath, "index.html"))
    );
  }

  app.use(jwt(jwtConfig));
  app.use(
    "/graphql",
    graphqlHttp(request => ({
      schema,
      context: { user: request.user },
    }))
  );
  app.use(onAuthError);
  app.get("/documents/:id/pdf", documentPdfHandler);
  app.listen(PORT, () => {
    console.log(`Publications started on port ${PORT}.`);
  });
}
Beispiel #9
0
export function build<T>(config: T) {
  const compiler = webpack(config)
  return new Promise((resolve, reject) => {
    compiler.run((err, stats) => {
      if (err) {
        return reject(err)
      }

      const messages = formatWebpackMessages(stats.toJson())
      if (messages.errors.length) {
        // Only keep the first error. Others are often indicative
        // of the same problem, but confuse the reader with noise.
        if (messages.errors.length > 1) {
          messages.errors.length = 1
        }
        return reject(new Error(messages.errors.join('\n\n')))
      }

      return resolve({
        stats,
        warnings: messages.warnings,
      })
    })
  })
}
export = () => {

  let options = {
    contentBase: 'dist/dev',
    colors: true,
    progress: true,
    watch: true,
    stats: {
      colors: true,
      progress: true
    }
  };

  new WebpackDevServer(webpack(config), options)
    .listen(
      config.devServer.port,
      config.devServer.host,
      (err: any) => {
        if(err) throw new gutil.PluginError("webpack-dev-server", err);
        // Server listening
        gutil.log(
          "[webpack-dev-server]",
          "http://" + config.devServer.host + ":" + config.devServer.port + "/webpack-dev-server/index.html");

        // keep the server alive or continue?
        // callback();

      });

};