UNPKG

@bincode/jekpack

Version:

[![npm version](https://badge.fury.io/js/%40bincode%2Fjekpack.svg)](https://badge.fury.io/js/%40bincode%2Fjekpack) [![Build Status](https://travis-ci.org/yfxie/jekpack.svg?branch=master)](https://travis-ci.org/yfxie/jekpack) [![codecov](https://codecov.io

100 lines (94 loc) 2.57 kB
const path = require('path'); const glob = require('glob'); const getConfigFilePath = require(path.resolve(process.env.JEKPACK_ROOT, 'lib/utils/getConfigFilePath')); const MiniCSSExtractPlugin = require('mini-css-extract-plugin'); const ASSET_PATH = path.join(process.env.JEKPACK_CONTEXT, 'src/assets'); const CopyPlugin = require('copy-webpack-plugin'); const { WebpackManifestPlugin } = require('webpack-manifest-plugin'); const devMode = process.env.NODE_ENV !== 'production'; const entryGenerator = () => { const pageEntries = glob.sync('**/main.{js,scss}', { cwd: ASSET_PATH, }).reduce((output, path) => { output[path.replace(/\.(js|scss)$/g, '')] = path; return output; }, {}); return { ...pageEntries, } }; module.exports = { context: process.env.JEKPACK_ROOT, entry: entryGenerator, devServer: { allowedHosts: "all", devMiddleware: { writeToDisk: true, }, }, output: { publicPath: '/assets/', }, module: { rules: [ { test: /\.(sa|sc|c)ss$/, use: [ devMode ? 'style-loader' : MiniCSSExtractPlugin.loader, 'css-loader', { loader: 'postcss-loader', options: { config: { path: path.dirname(getConfigFilePath('postcss.config.js')), } } }, { loader: 'sass-loader', options: { includePaths: [path.join(ASSET_PATH, 'stylesheets')] } }, ] }, { test: /\.(jpg|jpeg|png|gif|tiff|ico|svg|eot|otf|ttf|woff|woff2)(\?.*)?$/, use: [ { loader: 'file-loader', options: { name: 'media/[name].[hash:8].[ext]', } } ] } ] }, resolve: { modules: [ ASSET_PATH, path.resolve(process.env.JEKPACK_CONTEXT, 'node_modules'), path.resolve(process.env.JEKPACK_ROOT, 'node_modules'), ], }, resolveLoader: { modules: [path.resolve(process.env.JEKPACK_CONTEXT, 'node_modules'), 'node_modules'], }, plugins: [ new WebpackManifestPlugin({}), new CopyPlugin([ { from: path.resolve(ASSET_PATH, 'media'), to: 'media/[name].[hash].[ext]', toType: 'template', }, ], { // always copy for solving the issue of missing assets in manifest after rebuilding copyUnmodified: true, ignore: [ '.DS_Store', '.gitkeep', '.keep' ] }), new MiniCSSExtractPlugin({ filename: '[name]-[chunkhash].css', }), ], };