2021-05-20 22:09:15 +01:00
# Webpack config for Flarum JS/TS compilation
2018-02-24 16:29:19 +10:30
2018-06-16 14:34:12 +09:30
This package generates a [Webpack ](https://webpack.js.org ) config object that will compile JavaScript for use in Flarum.
## Usage
**webpack.config.js**
2018-02-24 16:29:19 +10:30
```js
var config = require('flarum-webpack-config');
2018-06-16 14:34:38 +09:30
module.exports = config(options);
2018-02-24 16:29:19 +10:30
```
2018-06-16 14:34:12 +09:30
To merge in custom Webpack config options, use [webpack-merge ](https://www.npmjs.com/package/webpack-merge ).
2018-06-16 14:34:38 +09:30
2021-05-13 00:05:27 +01:00
### Webpack Bundle Analyzer
You can view a visual representation of your JS Bundle by building with Webpack Bundle Analyzer.
Add another build script to your `package.json` like the one below:
```json
{
"analyze": "npx cross-env ANALYZER=true npm run build"
}
```
2021-05-12 01:28:31 +01:00
## Typescript
You'll need to configure a `tsconfig.json` file to ensure your IDE sets up Typescript support correctly.
For details about this, see the [`flarum/flarum-tsconfig` repository ](https://github.com/flarum/flarum-tsconfig )
2018-06-16 14:34:38 +09:30
## Options
### `useExtensions`
`Array<string>` , defaults to `[]` .
An array of extensions whose modules should be made available. This is a shortcut to add [`externals` ](https://webpack.js.org/configuration/externals/ ) configuration for extension modules. Imported extension modules will not be bundled, but will instead refer to the extension's exports included in the Flarum runtime (ie. `flarum.extensions["vendor/package"]` ).
For example, to access the Tags extension module within your extension:
**forum.js**
```js
2018-10-21 15:23:55 +10:30
import { Tag } from '@flarum/tags/forum ';
2018-06-16 14:34:38 +09:30
```
**webpack.config.js**
```js
module.exports = config({
2021-05-12 01:28:31 +01:00
useExtensions: ['flarum/tags'],
2018-06-16 14:34:38 +09:30
});
```