Comments (10)
As an FYI, https://github.com/GoogleChromeLabs/preload-webpack-plugin/releases/tag/v3.0.0-alpha.1 is out, including webpack 4 support (thanks to contributions from @toxic-johann)
You can give it a try via
$ npm install --save-dev preload-webpack-plugin@next
Please open a new issue with any feedback or issues you encounter.
from preload-webpack-plugin.
Do you set include
to be allAssets
?
It seems that there is a bug here https://github.com/GoogleChromeLabs/preload-webpack-plugin/blob/master/index.js#L241.
from preload-webpack-plugin.
Not yet, should I?
from preload-webpack-plugin.
It's better if you can provide your webapck.config
from preload-webpack-plugin.
/**
* Webpack Config for Javascript Bundling
*
* @package generator-kittn
* @author Lars Eichler <[email protected]>
*/
import webpack from 'webpack'
import { getIfUtils, removeEmpty } from 'webpack-config-utils'
import path from 'path'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import StylelintPlugin from 'stylelint-webpack-plugin'
import CleanWebpackPlugin from 'clean-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin'
import PreloadWebpackPlugin from 'preload-webpack-plugin'
import OptimizeCSSPlugin from 'optimize-css-assets-webpack-plugin'
const loadMinified = require('./load-minified')
const kittnConf = require('../config.json')
const nodeEnv = process.env.NODE_ENV || 'production'
const {
ifProduction,
ifDevelopment
} = getIfUtils(nodeEnv)
/*
|--------------------------------------------------------------------------
| Setting some paths for our Application
|--------------------------------------------------------------------------
*/
const ROOT_PATH = path.resolve(__dirname, '..')
const PUBLIC_PATH = path.join(ROOT_PATH, kittnConf.dist.webpackpublic)
const ASSETS_PATH = kittnConf.dist.webpackjsassets
const CSS_PATH = kittnConf.dist.webpackcssassets
const CSS_ROOT = path.resolve(ROOT_PATH, kittnConf.src.style)
const LOADER_PATH = path.join(ROOT_PATH, kittnConf.src.js)
/*
|--------------------------------------------------------------------------
| Hot Middleware Client
|--------------------------------------------------------------------------
*/
const hotClient =
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true&overlay=true'
/*
|--------------------------------------------------------------------------
| Defining Entry Points, could be used to manually split Parts of the Application, for example
| Admin Javascript and FrontEnd JavaScript
|--------------------------------------------------------------------------
*/
const entryPoints = kittnConf.src.jsEntryPoints
if (ifDevelopment()) {
Object.keys(entryPoints).forEach((entry) => entryPoints[entry] = [hotClient].concat(entryPoints[entry]))
}
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
function assetsPath(_path) {
return path.posix.join('assets/counselor/', _path);
}
const CSS_LOADERS = [
{
loader: 'css-loader',
options: {
autoprefixer: false,
sourceMap: true,
url: true
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
config: {
ctx: {
normalize: true
}
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
/*
|--------------------------------------------------------------------------
| return webpack config object
|--------------------------------------------------------------------------
*/
module.exports = {
mode: nodeEnv,
context: path.join(ROOT_PATH, 'src'),
entry: removeEmpty(entryPoints),
output: {
path: path.join(PUBLIC_PATH, ASSETS_PATH),
publicPath: ifDevelopment('/' + ASSETS_PATH, ASSETS_PATH),
filename: 'js/[name].js',
chunkFilename: 'js/[id].[chunkhash].js'
},
externals: {
Modernizr: 'Modernizr'
},
resolve: {
extensions: [
'.vue',
'.js'
],
modules: [resolve(kittnConf.src.base), resolve('node_modules')],
alias: {
appstyles$: path.resolve(CSS_ROOT, '_app.scss'),
components: path.resolve(LOADER_PATH, 'components/'),
atoms: path.resolve(LOADER_PATH, 'components/atoms/'),
molecules: path.resolve(LOADER_PATH, 'components/molecules/'),
organisms: path.resolve(LOADER_PATH, 'components/organisms/'),
templates: path.resolve(LOADER_PATH, 'components/templates/'),
assets: path.resolve(LOADER_PATH, 'assets/'),
api: path.resolve(LOADER_PATH, 'shared/api/'),
mixins: path.resolve(LOADER_PATH, 'shared/mixins/'),
store: path.resolve(LOADER_PATH, 'store'),
'package.json': resolve('/package.json'),
'vue-quill-editor': 'vue-quill-editor/src/editor.vue'
}
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
options: {
configFile: ifProduction('./.eslintrc.js', './.eslintrc-dev.js'),
formatter: require('eslint-friendly-formatter')
},
exclude: /node_modules/,
include: resolve(kittnConf.src.base)
},
{
test: /\.js$/,
use: 'babel-loader',
include: resolve(kittnConf.src.base),
exclude: /node_modules/
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
scss: ifProduction(
ExtractTextPlugin.extract({
use: [...CSS_LOADERS],
fallback: 'vue-style-loader',
}),
[{ loader: 'vue-style-loader'}, ...CSS_LOADERS]
),
}
}
},
{
test: /\.(eot|ttf|woff|woff2)(\?\S*)?$/,
loader: 'file-loader',
query: ifProduction({
outputPath: 'fonts/',
publicPath: kittnConf.dist.webpackFontsPath,
name: '[name].[ext]'
}, {
outputPath: 'fonts/',
publicPath: kittnConf.dist.webpackFontsPathDev,
name: '[name].[ext]'
})
},
{
test: /\.(png|jpe?g|gif)(\?\S*)?$/,
loader: 'url-loader',
options: {
fallback: 'file-loader'
}
},
{
test: /\.scss$/,
include: resolve(kittnConf.src.style),
exclude: [resolve('node_modules'), resolve('public/')],
use: ifProduction(ExtractTextPlugin.extract({
fallback: 'style-loader',
use: CSS_LOADERS,
}), ['style-loader', ...CSS_LOADERS]),
},
{
test: /\.css$/,
use: ifProduction(ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader'],
}), ['style-loader', 'css-loader'])
},
{
test: /\.svg$/,
loader: 'vue-svg-loader',
options: {
// optional [svgo](https://github.com/svg/svgo) options
svgo: {
plugins: [
{ removeDoctype: true },
{ removeComments: true }
]
}
}
}
]
},
plugins: removeEmpty([
ifProduction(
new CleanWebpackPlugin([
ASSETS_PATH + 'js/',
CSS_PATH
],
{
root: PUBLIC_PATH,
beforeEmit: true,
exclude: ['modernizr.js', 'style.css', 'style.css.map']
})
),
ifProduction(
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: true,
statsFilename: `${ROOT_PATH}/webpack/stats.json`,
logLevel: 'info'
})
),
ifDevelopment(new webpack.HotModuleReplacementPlugin()),
ifDevelopment(new webpack.NamedModulesPlugin()),
ifDevelopment(new webpack.NoEmitOnErrorsPlugin()),
ifDevelopment(new FriendlyErrorsWebpackPlugin()),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv)
}
}),
ifProduction(
new StylelintPlugin({
context: LOADER_PATH,
syntax: 'scss'
})
),
new ExtractTextPlugin({
filename: ifDevelopment('css/[name].css', 'css/[name].[chunkhash].css'),
allChunks: true
}),
ifProduction(
new OptimizeCSSPlugin({
cssProcessorOptions: {
safe: true
}
})
),
ifProduction(
new HtmlWebpackPlugin({
template: '../public/index.html',
filename: '../../index.html',
inject: true,
hash: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
serviceWorkerLoader: `<script>${loadMinified(path.join(__dirname, './service-worker-prod.js'))}</script>`
})
),
ifProduction(
new PreloadWebpackPlugin()
),
// service worker caching
new SWPrecacheWebpackPlugin({
cacheId: '{{ name }}',
filename: 'js/service-worker.js',
staticFileGlobs: ['../public/onlineberatung/**/*.{js,html,css}'],
minify: true
// stripPrefix: 'dist/'
})
])
}
from preload-webpack-plugin.
It's propably related to https://github.com/GoogleChromeLabs/preload-webpack-plugin/blob/master/index.js#L45, but I don't know if that function is available on webpack < 4
from preload-webpack-plugin.
This function is not available on webpack 4. It's weird that it's called on webpack 4.
from preload-webpack-plugin.
In that case, I don't have an idea :D
from preload-webpack-plugin.
v2.3.0 is not compatible with Webpack > 3. There's a v3 branch that's being prepared, so v3.0.0 should have Webpack 4 support once it's released.
from preload-webpack-plugin.
OK, so I wait for v3 to be released.
from preload-webpack-plugin.
Related Issues (20)
- Can I use prealod webpack plugin with Webpack 3xx ?
- Expo for web compatibility
- Publish v3 to npm HOT 5
- Add links based on webpackPreload/webpackPrefetch magic comments HOT 1
- working
- ability to remove crossorigin
- crossorigin='crossorigin' issue on fonts
- how to make it do a link with prefetch assets in include is asyncChunk
- The stylesheet file and the preloaded styles are not in the correct order HOT 1
- 'html-webpack-plugin-before-html-processing'. Hook was not found. HOT 2
- Bug of fileBlacklist shadow merge
- How to use in MPA config to load async chunks?
- assets'path inject incorrent
- How to preload some of assets
- Webpack 5 Support? HOT 4
- Merge changes from tag 3.0.0-beta.4 HOT 2
- Use regex in 'include' option
- assets inject incorrent(produce three files for one file) HOT 1
- Support imagesrcset and imagesizes
- Feature to opt-in to CORS preload requests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preload-webpack-plugin.