3 > [PureScript](http://www.purescript.org) loader for [webpack](http://webpack.github.io)
5 - Supports hot-reloading and rebuilding of single source files
6 - Dead code elimination using the `bundle` option
7 - Colorized build output using `purescript-psa` and the `psc: "psa"` option
11 Install with [npm](https://npmjs.org/package/purs-loader).
14 // For PureScript 0.9 and newer
15 npm install purs-loader --save-dev
18 npm install purs-loader@purescript-0.8 --save-dev
24 const webpackConfig = {
30 loader: 'purs-loader',
31 exclude: /node_modules/,
34 src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs']
43 Refer to the [purescript-webpack-example](https://github.com/ethul/purescript-webpack-example) for a more detailed example.
50 const loaderConfig = {
53 pscBundle: 'psc-bundle',
55 pscIde: false, // instant rebuilds using psc-ide-server (experimental)
56 pscIdeArgs: {}, // for example, to use different psc-ide-server port: {port: 4088}
57 pscIdeServerArgs: {}, // for example, to change the port { port: 4088 }
58 pscIdeColors: false, // defaults to true if psc === 'psa'
60 bundleOutput: 'output/bundle.js',
61 bundleNamespace: 'PS',
64 watch: false, // indicates if webpack is in watch mode
67 path.join('src', '**', '*.purs'),
68 // if pscPackage = false
69 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
70 // if pscPackage = true
71 // source paths reported by `psc-package sources`
76 ### `psc-ide` support (experimental)
78 Experimental support for instant rebuilds using `psc-ide-server` can be enabled
79 via the `pscIde: true` option.
80 You can use an already running `psc-ide-server` instance by specifying the port in `pscIdeArgs`,
81 if there is no server running this loader will start one for you.
83 ### `psc-package` support (experimental)
85 Set `pscPackage` query parameter to `true` to enable `psc-package` support. The `psc-package`-supplied source paths
86 will be appended to `src` parameter.
90 #### Slower webpack startup after enabling psc-ide support?
92 By default, the psc-ide-server will be passed the globs from query.src, this is
93 helpful for other tools using psc-ide-server (for example IDE plugins), however
94 it might result in a slower initial webpack startup time (rebuilds are not
95 affected). To override the default behaviour, add:
96 `pscIdeServerArgs: { "_": ['your/*globs/here'] }` to the loader config
98 #### Errors not being displayed in watch mode?
100 When the `watch` option is set to `true`, psc errors are appended to
101 webpack's compilation instance errors array and not passed back as an
102 error to the loader's callback. This may result in the error not being
103 reported by webpack. To display errors, the following plugin may be added
104 to the webpack config.
107 const webpackConfig = {
111 this.plugin('done', function(stats){
112 process.stderr.write(stats.toString('errors-only'));
120 #### Error `spawn ENOENT`
122 This is caused when the loader tries to spawn a binary that does not exists
123 (`file or directory not found`). If you call webpack like `webpack` or
124 `webpack --watch`, then you need to ensure that all required binaries that the
125 loader depends on are available in your `$PATH`.
127 If you use `npm run` and `npm start` on NixOS, then it will first attempt to find
128 binaries in `node_packages/.bin`. If you have the compiler installed through `npm`
129 and it finds it there, this will cause `ENOENT`on Nix, because
130 [the binary needs to be patched first, because npm will install the binary that is
131 linked with /lib64/ld-linux-x86-64.so.2 - a file that will not exist at that path in
132 NixOS](https://github.com/ethul/purescript-webpack-example/issues/5#issuecomment-282492131).
133 The solution is to simply use the compiler from `haskellPackages.purescript` and
134 make sure that it's available in `$PATH`. For more information about how to make
135 it work on Nix, see [Purescript Webpack Example](https://github.com/ethul/purescript-webpack-example#using-globally-installed-binaries)