Sépare les configurations Webpack de mon-entreprise et publicodes

pull/1377/head
Maxime Quandalle 2021-01-18 15:02:24 +01:00
parent 2fcc9c2442
commit cac1d13164
8 changed files with 166 additions and 146 deletions

View File

@ -5,6 +5,103 @@ const path = require('path')
const { EnvironmentPlugin } = require('webpack')
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
module.exports.styleLoader = (styleLoader) => ({
test: /\.css$/,
use: [
{ loader: styleLoader },
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
},
],
})
module.exports.commonLoaders = ({ legacy = false } = {}) => {
const babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: true,
rootMode: 'upward',
presets: [
[
'@babel/preset-env',
{
targets: !legacy
? {
esmodules: true,
}
: {
esmodules: false,
browsers: ['ie 11'],
},
useBuiltIns: 'entry',
corejs: '3',
},
],
],
},
}
return [
{
test: /\.(js|ts|tsx)$/,
use: babelLoader,
exclude: /node_modules|dist/,
},
{
test: /\.(jpe?g|png|svg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
name: 'images/[name].[ext]',
},
},
],
},
{
test: /\.(ttf|woff2?)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts',
publicPath: '/fonts',
},
},
],
},
{
test: /\.yaml$/,
use: ['json-loader', 'yaml-loader'],
},
{
test: /\.toml$/,
use: ['toml-loader'],
},
{
test: /\.ne$/,
use: [babelLoader, 'nearley-loader'],
},
{
test: /\.md$/,
use: ['raw-loader'],
},
{
test: /\.pdf$/,
use: ['file-loader'],
},
]
}
module.exports.default = {
resolve: {
alias: {

View File

@ -2,8 +2,12 @@
const { map } = require('ramda')
const webpack = require('webpack')
const { commonLoaders, styleLoader } = require('../webpack/common')
const { HTMLPlugins, default: common } = require('./webpack.common')
const {
HTMLPlugins,
styleLoader,
commonLoaders,
default: common,
} = require('./webpack.common')
module.exports = {
...common,

View File

@ -1,7 +1,11 @@
/* eslint-env node */
const { HTMLPlugins, default: common } = require('./webpack.common')
const { commonLoaders, styleLoader } = require('../webpack/common')
const {
HTMLPlugins,
styleLoader,
commonLoaders,
default: common,
} = require('./webpack.common')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')

View File

@ -2,7 +2,7 @@ const { map } = require('ramda')
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
const prod = require('./webpack.prod')
const { commonLoaders, styleLoader } = require('../webpack/common')
const { commonLoaders, styleLoader } = require('./webpack.common')
const { EnvironmentPlugin } = require('webpack')

View File

@ -1,7 +1,26 @@
/* eslint-env node */
const path = require('path')
const { commonLoaders } = require('../../webpack/common')
const babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: true,
rootMode: 'upward',
presets: [
[
'@babel/preset-env',
{
targets: {
esmodules: true,
},
useBuiltIns: 'entry',
corejs: '3',
},
],
],
},
}
const common = {
resolve: {
@ -10,30 +29,39 @@ const common = {
mode: process.env.NODE_ENV,
entry: path.resolve(__dirname, 'source', 'index.ts'),
module: {
rules: commonLoaders({ file: false }),
rules: [
{
test: /\.(js|ts|tsx)$/,
use: babelLoader,
exclude: /node_modules|dist/,
},
{
test: /\.ne$/,
use: [babelLoader, 'nearley-loader'],
},
{
test: /\.yaml$/,
use: ['json-loader', 'yaml-loader'],
},
],
},
}
module.exports = [
// Config for UMD export (browser / node)
{
...common,
output: {
filename: 'index.js',
library: 'publicodes',
libraryTarget: 'umd',
globalObject: 'this',
},
externals:
// Every non-relative module is external
/^[a-z\-0-9]+$/,
},
process.env.NODE_ENV === 'production' && {
...common,
output: {
filename: 'publicodes.min.js',
library: 'publicodes',
libraryTarget: 'global',
},
},
].filter(Boolean)
const output =
process.env.NODE_ENV === 'production'
? {
filename: 'publicodes.min.js',
library: 'publicodes',
libraryTarget: 'global',
}
: {
filename: 'index.js',
library: 'publicodes',
libraryTarget: 'umd',
globalObject: 'this',
}
module.exports = {
...common,
output,
}

View File

@ -1,24 +1,13 @@
const { commonLoaders } = require('../../webpack/common')
const { EnvironmentPlugin } = require('webpack')
const prodConfig = require('./webpack.config')
module.exports = {
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
...prodConfig,
mode: 'development',
output: {
devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]',
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
},
mode: 'development',
module: {
rules: [
...commonLoaders(),
{
test: /\.css$/,
use: ['css-loader', 'postcss-loader'],
},
],
},
plugins: [
new EnvironmentPlugin({
NODE_ENV: 'test',

View File

@ -1,102 +0,0 @@
/* eslint-env node */
module.exports.styleLoader = (styleLoader) => ({
test: /\.css$/,
use: [
{ loader: styleLoader },
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
},
],
})
module.exports.commonLoaders = ({ legacy = false, file = true } = {}) => {
const babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: true,
rootMode: 'upward',
presets: [
[
'@babel/preset-env',
{
targets: !legacy
? {
esmodules: true,
}
: {
esmodules: false,
browsers: ['ie 11'],
},
useBuiltIns: 'entry',
corejs: '3',
},
],
],
},
}
return [
{
test: /\.(js|ts|tsx)$/,
use: babelLoader,
exclude: /node_modules|dist/,
},
...(file
? [
{
test: /\.(jpe?g|png|svg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
name: 'images/[name].[ext]',
},
},
],
},
]
: []),
{
test: /\.(ttf|woff2?)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts',
publicPath: '/fonts',
},
},
],
},
{
test: /\.yaml$/,
use: ['json-loader', 'yaml-loader'],
},
{
test: /\.toml$/,
use: ['toml-loader'],
},
{
test: /\.ne$/,
use: [babelLoader, 'nearley-loader'],
},
{
test: /\.md$/,
use: ['raw-loader'],
},
{
test: /\.pdf$/,
use: ['file-loader'],
},
]
}