split webpack build in chunks

This commit is contained in:
daniel-j 2019-10-08 10:44:04 +02:00
parent b9cfa96446
commit 6cbc71e17b
3 changed files with 272 additions and 4 deletions

View file

@ -18,7 +18,7 @@
"content_scripts": [
{
"matches": ["https://www.fimfiction.net/*", "http://www.fimfiction.net/*"],
"js": ["build/fimfic2epub.js"],
"js": ["build/vendors~fimfic2epub.js", "build/fimfic2epub.js"],
"css": ["inject.css"]
}
],

View file

@ -19,7 +19,7 @@ import removeNPMAbsolutePaths from 'removeNPMAbsolutePaths'
// script
import standard from 'gulp-standard'
import webpack from 'webpack'
import webpackConfig from './webpack.config.babel.js'
import webpackConfig from './webpack.config.js'
const inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
@ -186,10 +186,10 @@ gulp.task('watch:webpack', () => {
})
gulp.task('lint', () => {
return lintPipe(gulp.src(['gulpfile.babel.js', 'webpack.config.babel.js', 'src/**/*.js']))
return lintPipe(gulp.src(['gulpfile.babel.js', 'webpack.config.js', 'src/**/*.js']))
})
gulp.task('watch:lint', () => {
return watch(['src/**/*.js', 'gulpfile.babel.js', 'webpack.config.babel.js'], watchOpts, (file) => {
return watch(['src/**/*.js', 'gulpfile.babel.js', 'webpack.config.js'], watchOpts, (file) => {
return lintPipe(gulp.src(file.path))
})
})

268
webpack.config.js Normal file
View file

@ -0,0 +1,268 @@
import path from 'path'
import nodeExternals from 'webpack-node-externals'
let inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
const bundleExtensionConfig = {
entry: {
eventPage: ['./src/eventPage'],
fimfic2epub: ['regenerator-runtime/runtime', './src/main']
},
output: {
path: path.join(__dirname, '/'),
filename: './extension/build/[name].js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/env', {
targets: {
browsers: ['chrome 50', 'firefox 47']
},
modules: false
}]]
}
}
},
{
test: /\.styl$/,
use: ['raw-loader', 'stylus-loader']
},
{
test: /\.ttf$/,
use: 'binary-loader'
}
]
},
resolve: {
extensions: ['.js', '.json', '.styl'],
modules: [
path.resolve('./src'),
'node_modules'
]
},
node: {
fs: 'empty'
},
externals: ['request'],
plugins: [
// new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)()
],
performance: {
hints: false
},
optimization: {
concatenateModules: inProduction,
minimize: inProduction,
splitChunks: {
chunks: 'all'
}
},
devtool: 'source-map',
mode: inProduction ? 'production' : 'development'
}
const bundleNpmModuleConfig = {
entry: './src/FimFic2Epub',
output: {
path: path.join(__dirname, '/'),
filename: './dist/fimfic2epub.js',
libraryTarget: 'commonjs2'
},
target: 'node',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
sourceMaps: !inProduction,
presets: [['@babel/env', {
targets: {
node: '8.0.0'
}
}]]
}
}
},
{
test: /\.styl$/,
use: ['raw-loader', 'stylus-loader']
},
{
test: /\.ttf$/,
use: 'binary-loader'
}
]
},
resolve: {
extensions: ['.js', '.json', '.styl', '.node'],
modules: [
path.resolve('./src'),
'node_modules'
]
},
node: {
__dirname: false
},
externals: [nodeExternals({ whitelist: [/^babel-runtime/, /fontawesome-webfont\.ttf/] })],
plugins: [],
performance: {
hints: false
},
optimization: {
concatenateModules: inProduction,
minimize: inProduction
},
devtool: 'nosources-source-map',
mode: inProduction ? 'production' : 'development'
}
const bundleNpmBinaryConfig = {
entry: './src/cli',
output: {
path: path.join(__dirname, '/'),
filename: './build/fimfic2epub.js'
},
target: 'node',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
sourceMaps: !inProduction,
presets: [['@babel/env', {
targets: {
node: '8.0.0'
}
}]]
}
}
}
]
},
resolve: {
extensions: ['.js', '.json', '.node'],
modules: [
path.resolve('./src'),
'node_modules'
]
},
node: {
__dirname: false
},
externals: [nodeExternals(), {
'./FimFic2Epub': 'require(\'../dist/fimfic2epub\')',
'../package.json': 'require(\'../package.json\')'
}],
plugins: [],
performance: {
hints: false
},
optimization: {
concatenateModules: inProduction,
minimize: inProduction
},
devtool: false,
mode: inProduction ? 'production' : 'development'
}
const bundleStaticNpmModuleConfig = {
entry: './src/cli',
output: {
path: path.join(__dirname, '/'),
filename: './build/fimfic2epub-static.js'
},
target: 'node',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
sourceMaps: !inProduction,
presets: [['@babel/env', {
targets: {
node: 'current'
}
}]]
}
}
},
{
test: /\.styl$/,
use: ['raw-loader', 'stylus-loader']
},
{
test: /\.ttf$/,
use: 'binary-loader'
}
]
},
resolve: {
extensions: ['.js', '.json', '.styl', '.node'],
modules: [
path.resolve('./bin'),
'node_modules'
]
},
node: {
__dirname: false
},
plugins: [],
performance: {
hints: false
},
optimization: {
concatenateModules: inProduction,
minimize: inProduction
},
devtool: false,
mode: inProduction ? 'production' : 'development'
}
export default [
bundleExtensionConfig,
bundleNpmModuleConfig,
bundleNpmBinaryConfig,
bundleStaticNpmModuleConfig
]