-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#62] Add the initial version of Brunch & Webpack guides #63
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## Brunch Configuration for Torch | ||
|
||
### Using Sass Variables | ||
|
||
Update your `brunch-config.js` SASS settings to make it watch your node_modules directory: | ||
|
||
NOTE: We recommend you use yarn for best results rather than npm. NPM >5.0 is currently less stable than yarn. | ||
|
||
```js | ||
plugins: { | ||
sass: { | ||
mode: 'native', | ||
includePaths: ['node_modules'] | ||
} | ||
} | ||
``` | ||
|
||
### Using Precompiled Assets | ||
|
||
1. Add `node_modules` to the watched directories for `stylesheets`. | ||
|
||
```js | ||
stylesheets: { | ||
joinTo: { | ||
'css/app.css': /^(web|node_modules)/ | ||
} | ||
} | ||
``` | ||
|
||
2. Add `torch` to the npm configuration: | ||
|
||
```js | ||
npm: { | ||
enabled: true | ||
styles: { | ||
torch: [ | ||
'priv/static/torch.css' | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
## Webpack Configuration for Torch | ||
|
||
Below is an example `webpack.config.js` (version 3.0.0) that imports Torch javascript, css, | ||
fonts, & images correctly. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe note: "We recommend you use |
||
|
||
NOTE: We recommend you use yarn for best results rather than npm. NPM >5.0 is currently less stable than yarn. | ||
|
||
```javascript | ||
var path = require('path') | ||
var ExtractTextPlugin = require('extract-text-webpack-plugin') | ||
var CopyWebpackPlugin = require('copy-webpack-plugin') | ||
var env = process.env.MIX_ENV || 'dev' | ||
var isProduction = (env === 'prod') | ||
|
||
module.exports = { | ||
entry: { | ||
'app': ['./js/app.js', './css/app.sass'] | ||
}, | ||
|
||
output: { | ||
path: path.resolve(__dirname, '../priv/static/'), | ||
filename: 'js/[name].js' | ||
}, | ||
|
||
devtool: 'source-map', | ||
|
||
module: { | ||
rules: [{ | ||
// SASS Loader | ||
test: /\.(sass|scss)$/, | ||
include: /css/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: [ | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
minimize: isProduction, | ||
sourceMap: true | ||
} | ||
}, | ||
{ | ||
loader: 'resolve-url-loader' | ||
}, | ||
{ | ||
loader: 'sass-loader', | ||
options: { | ||
sourceComments: !isProduction, | ||
sourceMap: true | ||
} | ||
} | ||
] | ||
}) | ||
}, { | ||
// JS Loader | ||
test: /\.js?$/, | ||
include: /js/, | ||
exclude: /node_modules/, | ||
use: [{ | ||
loader: 'babel-loader', | ||
query: { | ||
presets: ['es2015'], | ||
plugins: [], | ||
cacheDirectory: true | ||
} | ||
}] | ||
}, | ||
{ | ||
// Image Loader | ||
test: /\.(png|svg|jpg|gif)$/, | ||
exclude: /(fonts|node_modules)/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: '../images/' | ||
} | ||
}] | ||
}, | ||
{ | ||
// Font Loader | ||
test: /\.(woff|woff2|eot|ttf|otf|svg)$/, | ||
exclude: /(images|node_modules)/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'fonts/' | ||
} | ||
}] | ||
}, | ||
{ | ||
// Torch Image Loader | ||
test: /torch.+images.+\.(png|svg|jpg|gif)$/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'images/', | ||
publicPath: '../' | ||
} | ||
}] | ||
}, | ||
{ | ||
// Torch Font Loader | ||
test: /torch.+fonts.+\.(woff|woff2|eot|ttf|otf|svg)$/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'fonts/', | ||
publicPath: '../' | ||
} | ||
}] | ||
}] | ||
}, | ||
|
||
plugins: [ | ||
new CopyWebpackPlugin([{ from: './static/images', to: 'images' }]), | ||
new CopyWebpackPlugin([{ from: './static/robots.txt' }]), | ||
new ExtractTextPlugin('css/app.css') | ||
] | ||
} | ||
``` | ||
|
||
### Break Down | ||
|
||
#### Sass Loader | ||
|
||
This is a pretty standard sass loader including all `.sass` or `.scss` files in the | ||
`/css/` directory. | ||
|
||
```javascript | ||
{ | ||
// SASS Loader | ||
test: /\.(sass|scss)$/, | ||
include: /css/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: [ | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
minimize: isProduction, | ||
sourceMap: true | ||
} | ||
}, | ||
{ | ||
loader: 'resolve-url-loader' | ||
}, | ||
{ | ||
loader: 'sass-loader', | ||
options: { | ||
sourceComments: !isProduction, | ||
sourceMap: true | ||
} | ||
} | ||
] | ||
}) | ||
} | ||
``` | ||
|
||
#### JS Loader | ||
|
||
Also a pretty standard JS loader, including all files with the `.js` extension withing | ||
the `/js/` folder and excluding `node_modules`. | ||
|
||
```javascript | ||
{ | ||
// JS Loader | ||
test: /\.js?$/, | ||
include: /js/, | ||
exclude: /node_modules/, | ||
use: [{ | ||
loader: 'babel-loader', | ||
query: { | ||
presets: ['es2015'], | ||
plugins: [], | ||
cacheDirectory: true | ||
} | ||
}] | ||
} | ||
``` | ||
|
||
#### Font & Image Loaders | ||
|
||
The first set of font & image loaders load images & fonts within your project, while the | ||
Torch font & image loaders load fonts and images from torch into the `priv/static` directory. | ||
|
||
```javascript | ||
{ | ||
// Image Loader | ||
test: /\.(png|svg|jpg|gif)$/, | ||
exclude: /(fonts|node_modules)/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: '../images/' | ||
} | ||
}] | ||
}, | ||
{ | ||
// Font Loader | ||
test: /\.(woff|woff2|eot|ttf|otf|svg)$/, | ||
exclude: /(images|node_modules)/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'fonts/' | ||
} | ||
}] | ||
}, | ||
{ | ||
// Torch Image Loader | ||
test: /torch.+images.+\.(png|svg|jpg|gif)$/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'images/', | ||
publicPath: '../' | ||
} | ||
}] | ||
}, | ||
{ | ||
// Torch Font Loader | ||
test: /torch.+fonts.+\.(woff|woff2|eot|ttf|otf|svg)$/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'fonts/', | ||
publicPath: '../' | ||
} | ||
}] | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe note: "We recommend you use yarn for best results rather than npm."