Guest User

Untitled

a guest
Dec 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. import {
  2. FuseBox, EnvPlugin, QuantumPlugin, WebIndexPlugin, CSSPlugin,
  3. JSONPlugin, Sparky, File, CopyPlugin, WorkFlowContext, BabelPlugin
  4. } from "fuse-box";
  5. import {BuildOptions, getCommonBuildOptions, getEnvironments, NodeEnv, OcastEnv} from "./BuildOptions";
  6.  
  7. /**
  8. * Sets up a FuseBox ready to either run a development server or produce builds.
  9. * All required configuration is already hardcoded in this function.
  10. * You may however choose to pass in additional options to customize your dev or build experience to your liking.
  11. *
  12. * NOTE: Running this function only sets up and configures the Bundle and FuseBox interfaces.
  13. * You will have to interact with these interfaces to proceed with serving or building.
  14. * See fuse-box docs for more information.
  15. *
  16. * @returns {{vendor: Bundle; app: Bundle; fuse: FuseBox}}
  17. */
  18. function setupFuse (ocastEnv: OcastEnv, nodeEnv: NodeEnv, options: BuildOptions = {}) {
  19. const fuse = FuseBox.init({
  20. homeDir: "app",
  21. sourceMaps: {project: options.sourceMaps, vendor: false},
  22. hash: options.hashFilenames,
  23. modulesFolder: "app",
  24. alias: {
  25. src: "~/src/",
  26. config: "~/config/"
  27. },
  28. target: "browser",
  29. output: `${options.outputFolder}/$name.js`,
  30. warnings: true,
  31. cache: options.hmr, // fuse-box requires cache to be on to support hmr
  32. log: options.log,
  33. debug: options.debug,
  34. tsConfig: "tsconfig.json",
  35. useTypescriptCompiler: false,
  36. plugins: [
  37. EnvPlugin({
  38. NODE_ENV: JSON.stringify(nodeEnv),
  39. OCAST_CONFIG: JSON.stringify(ocastEnv)
  40. }),
  41. BabelPlugin({
  42. test: /\.jsx?$/,
  43. extensions: [".jsx", ".js"],
  44. config: {
  45. sourceMaps: options.sourceMaps,
  46. presets: ["flow", "react", "stage-0"]
  47. }
  48. }),
  49. WebIndexPlugin({title: "Ocast", path: "."}),
  50. CopyPlugin({files: ["*.png", "*.jpg", "*.ogg"], dest: "assets", useDefault: false}),
  51. CSSPlugin(),
  52. JSONPlugin(),
  53. options.minify ?
  54. QuantumPlugin({
  55. treeshake: true,
  56. uglify: true
  57. }) : undefined
  58. ]
  59. });
  60.  
  61. const vendor = fuse.bundle("vendor");
  62. //.instructions(`~ src/client.js`);
  63.  
  64. const app = fuse.bundle("app")
  65. .instructions(`!> [src/client.js]`);
  66.  
  67. if (options.hmr) {
  68. app.hmr();
  69. }
  70.  
  71. return {vendor, app, fuse};
  72. }
  73.  
  74. /**
  75. * An extension of `setupFuse()` that also reads the ocast and node environment settings
  76. * from the system environment variables and defaults BuildOptions to options
  77. * common for the environments found (See `getCommonBuildOptions()`).
  78. * You can extend these options using `additionalOptions`.
  79. */
  80. function autoSetupFuse (additionalOptions: BuildOptions = {}) {
  81. const {ocastEnv, nodeEnv} = getEnvironments();
  82. const options = {
  83. ...getCommonBuildOptions(ocastEnv, nodeEnv),
  84. ...additionalOptions
  85. };
  86.  
  87. return {
  88. ...setupFuse(ocastEnv, nodeEnv, options),
  89. options
  90. };
  91. }
  92.  
  93.  
  94. /**
  95. * Serves ocast through the fuse-box development server.
  96. */
  97. Sparky.task("dev-server", () => {
  98. const {fuse, app} = autoSetupFuse();
  99. app.watch();
  100. fuse.dev();
  101. return fuse.run();
  102. });
  103.  
  104. /**
  105. * Builds ocast to the configured output folder
  106. */
  107. Sparky.task("build", () => {
  108. const {fuse, options} = autoSetupFuse();
  109. Sparky.src(options.outputFolder).clean(options.outputFolder);
  110. return fuse.run();
  111. });
Add Comment
Please, Sign In to add comment