]> git.immae.eu Git - github/fretlink/purs-loader.git/blob - README.md
Sourcemaps for ide rebuild (#118)
[github/fretlink/purs-loader.git] / README.md
1 # purs-loader
2
3 > [PureScript](http://www.purescript.org) loader for [webpack](http://webpack.github.io)
4
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
8
9 ## Install
10
11 Install with [npm](https://npmjs.org/package/purs-loader).
12
13 ```
14 // For PureScript 0.11 and newer
15 npm install purs-loader --save-dev
16
17 // For PureScript 0.9 and 0.10
18 npm install purs-loader@purescript-0.9 --save-dev
19
20 // For PureScript 0.8
21 npm install purs-loader@purescript-0.8 --save-dev
22 ```
23
24 ## Example
25
26 ```javascript
27 const webpackConfig = {
28 // ...
29 loaders: [
30 // ...
31 {
32 test: /\.purs$/,
33 loader: 'purs-loader',
34 exclude: /node_modules/,
35 query: {
36 psc: 'psa',
37 src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs']
38 }
39 }
40 // ...
41 ]
42 // ...
43 }
44 ```
45
46 Refer to the [purescript-webpack-example](https://github.com/ethul/purescript-webpack-example) for a more detailed example.
47
48 ### Options
49
50 Default options:
51
52 ```javascript
53 const loaderConfig = {
54 psc: null, // purs compile
55 pscArgs: {},
56 pscBundle: null, // purs bundle
57 pscBundleArgs: {},
58 pscIde: false, // instant rebuilds using psc-ide-server (experimental)
59 pscIdeClient: null, // purs ide client
60 pscIdeClientArgs: {}, // for example, to use different port {port: 4088}
61 pscIdeServer: null, // purs ide server
62 pscIdeServerArgs: {}, // for example, to change the port {port: 4088}
63 pscIdeRebuildArgs: {} // for example, for sourcemaps {codegen: ['js', 'sourcemaps']}
64 pscIdeColors: false, // defaults to true if psc === 'psa'
65 pscPackage: false,
66 bundleOutput: 'output/bundle.js',
67 bundleNamespace: 'PS',
68 bundle: false,
69 warnings: true,
70 watch: false, // indicates if webpack is in watch mode
71 output: 'output',
72 src: [
73 path.join('src', '**', '*.purs'),
74 // if pscPackage = false
75 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
76 // if pscPackage = true
77 // source paths reported by `psc-package sources`
78 ]
79 }
80 ```
81
82 ### `psc-ide` support (experimental)
83
84 Experimental support for instant rebuilds using `psc-ide-server` can be enabled
85 via the `pscIde: true` option.
86 You can use an already running `psc-ide-server` instance by specifying the port in `pscIdeArgs`,
87 if there is no server running this loader will start one for you.
88
89 ### `psc-package` support (experimental)
90
91 Set `pscPackage` query parameter to `true` to enable `psc-package` support. The `psc-package`-supplied source paths
92 will be appended to `src` parameter.
93
94 ### Troubleshooting
95
96 #### Slower webpack startup after enabling psc-ide support?
97
98 By default, the psc-ide-server will be passed the globs from query.src, this is
99 helpful for other tools using psc-ide-server (for example IDE plugins), however
100 it might result in a slower initial webpack startup time (rebuilds are not
101 affected). To override the default behaviour, add:
102 `pscIdeServerArgs: { "_": ['your/*globs/here'] }` to the loader config
103
104 #### Errors not being displayed in watch mode?
105
106 When the `watch` option is set to `true`, psc errors are appended to
107 webpack's compilation instance errors array and not passed back as an
108 error to the loader's callback. This may result in the error not being
109 reported by webpack. To display errors, the following plugin may be added
110 to the webpack config.
111
112 ```javascript
113 const webpackConfig = {
114 // ...
115 plugins: [
116 function(){
117 this.plugin('done', function(stats){
118 process.stderr.write(stats.toString('errors-only'));
119 });
120 }
121 ]
122 // ...
123 }
124 ```
125
126 #### Error `spawn ENOENT`
127
128 This is caused when the loader tries to spawn a binary that does not exists
129 (`file or directory not found`). If you call webpack like `webpack` or
130 `webpack --watch`, then ensure that all required binaries that the
131 loader depends on are available in your `$PATH`.
132
133 If you run webpack through an npm script (e.g., npm run or npm start) on NixOS,
134 then it will first attempt to find binaries in `node_packages/.bin`.
135 If you have the compiler installed through `npm` and it finds it there, this will
136 cause `ENOENT`on Nix, because [the binary needs to be patched first, but npm will
137 install the binary that is linked with /lib64/ld-linux-x86-64.so.2 - a file that
138 will not exist at that path in NixOS](https://github.com/ethul/purescript-webpack-example/issues/5#issuecomment-282492131).
139 The solution is to simply use the compiler from `haskellPackages.purescript` and
140 make sure that it's available in `$PATH`. For more information about how to make
141 it work on Nix, see [Purescript Webpack Example](https://github.com/ethul/purescript-webpack-example#using-globally-installed-binaries)