diff --git a/mon-entreprise/webpack.common.js b/mon-entreprise/webpack.common.js index ecd966921..a8188f9ba 100644 --- a/mon-entreprise/webpack.common.js +++ b/mon-entreprise/webpack.common.js @@ -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: { diff --git a/mon-entreprise/webpack.dev.js b/mon-entreprise/webpack.dev.js index d716a87d9..a2e2b8f9e 100644 --- a/mon-entreprise/webpack.dev.js +++ b/mon-entreprise/webpack.dev.js @@ -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, diff --git a/mon-entreprise/webpack.prod.js b/mon-entreprise/webpack.prod.js index c843137f3..ffb190e9e 100644 --- a/mon-entreprise/webpack.prod.js +++ b/mon-entreprise/webpack.prod.js @@ -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') diff --git a/mon-entreprise/webpack.prod.legacyBrowser.js b/mon-entreprise/webpack.prod.legacyBrowser.js index 2795c781b..c754b1e43 100644 --- a/mon-entreprise/webpack.prod.legacyBrowser.js +++ b/mon-entreprise/webpack.prod.legacyBrowser.js @@ -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') diff --git a/publicodes/test/serializeEvaluation.test.js b/publicodes/core/test/serializeEvaluation.test.js similarity index 100% rename from publicodes/test/serializeEvaluation.test.js rename to publicodes/core/test/serializeEvaluation.test.js diff --git a/publicodes/core/webpack.config.js b/publicodes/core/webpack.config.js index dda43c054..387be12e1 100644 --- a/publicodes/core/webpack.config.js +++ b/publicodes/core/webpack.config.js @@ -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, +} diff --git a/publicodes/core/webpack.test.js b/publicodes/core/webpack.test.js index 92723c822..ee4af3cb0 100644 --- a/publicodes/core/webpack.test.js +++ b/publicodes/core/webpack.test.js @@ -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', diff --git a/webpack/common.js b/webpack/common.js deleted file mode 100644 index 5ca543ec2..000000000 --- a/webpack/common.js +++ /dev/null @@ -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'], - }, - ] -}