Last active
January 16, 2019 15:03
-
-
Save carlwood/f66acac53eb7d0fb925e619005d79690 to your computer and use it in GitHub Desktop.
Drupal 8 webpack
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
global-styling: | |
js: | |
build/js/vendor.js: {} | |
build/js/main.js: {} | |
dependencies: | |
- core/drupal | |
css: | |
theme: | |
build/css/main.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
{ | |
"name": "d8-webpack", | |
"version": "1.0.0", | |
"description": "[](https://travis-ci.org/drupal-composer/drupal-project)", | |
"main": "app.js", | |
"scripts": { | |
"start": "webpack --mode development --watch --config webpack.dev.js", | |
"build": "webpack --mode production --config webpack.prod.js", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"@babel/core": "^7.2.2", | |
"@babel/plugin-syntax-dynamic-import": "^7.2.0", | |
"@babel/preset-env": "^7.2.2", | |
"autoprefixer": "^9.4.4", | |
"babel-loader": "^8.0.5", | |
"clean-webpack-plugin": "^1.0.0", | |
"css-loader": "^2.1.0", | |
"cssnano": "^4.1.8", | |
"eslint": "^5.3.0", | |
"eslint-config-airbnb-base": "^13.1.0", | |
"eslint-loader": "^2.1.1", | |
"eslint-plugin-import": "^2.14.0", | |
"html-webpack-plugin": "^3.2.0", | |
"mini-css-extract-plugin": "^0.5.0", | |
"node-sass": "^4.11.0", | |
"postcss-loader": "^3.0.0", | |
"postcss-preset-env": "^6.5.0", | |
"sass-loader": "^7.1.0", | |
"style-loader": "^0.23.1", | |
"webpack": "^4.28.1", | |
"webpack-cli": "^3.2.1", | |
"webpack-dev-server": "^3.1.14", | |
"webpack-merge": "^4.2.1" | |
} | |
} |
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
// webpack v4 | |
const path = require('path'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const themePath = path.resolve(__dirname, 'web/themes/custom/mytheme'); // Replace theme folder with your own | |
const themeJsPath = path.resolve(__dirname, `${themePath}/js`); | |
const themeBuildFolder = path.resolve(__dirname, `${themePath}/build`); | |
module.exports = { | |
target: 'web', | |
entry: { | |
main: path.resolve(__dirname, `${themeJsPath}/app.js`) | |
}, | |
output: { | |
path: path.resolve(__dirname, themeBuildFolder), | |
filename: 'js/[name].js', | |
publicPath: '/' | |
}, | |
optimization: { | |
splitChunks: { | |
cacheGroups: { | |
vendor: { | |
test: /node_modules/, | |
chunks: 'all', | |
name: 'vendor', | |
enforce: true | |
} | |
} | |
} | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader' | |
} | |
}, | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'eslint-loader', | |
options: { | |
failOnError: true | |
} | |
} | |
}, | |
{ | |
test: /\.scss$/, | |
use: [ | |
'style-loader', | |
MiniCssExtractPlugin.loader, | |
'css-loader', | |
'postcss-loader', | |
'sass-loader' | |
] | |
} | |
] | |
}, | |
plugins: [ | |
new CleanWebpackPlugin(themeBuildFolder, {} ), | |
new MiniCssExtractPlugin({ | |
filename: 'css/main.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
const merge = require('webpack-merge'); | |
const baseConfig = require('./webpack.common.js'); | |
module.exports = merge(baseConfig, { | |
devtool: 'inline-source-map' | |
}); |
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
// Empty for now | |
const merge = require('webpack-merge'); | |
const baseConfig = require('./webpack.common.js'); | |
module.exports = merge(baseConfig, { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When developing a D8 site, ensure that ' Aggregate CSS files' and 'Aggregate JavaScript files' checkboxes are unticked in
admin/config/development/performance