From e4964b34513e828d5cc9f2b278d794d892895277 Mon Sep 17 00:00:00 2001 From: Ghislain Beaulac Date: Mon, 16 Mar 2020 17:39:32 -0400 Subject: [PATCH] feat(build): tweak build to use tsc and test with sf lwc --- packages/common/package.json | 5 +- packages/common/typings/global.d.ts | 1 + .../common/typings/lodash.isequal/index.d.ts | 1 + packages/common/webpack.config.js | 89 ------------------- packages/vanilla-bundle/package.json | 7 +- packages/vanilla-bundle/tsconfig.json | 72 +++++++-------- 6 files changed, 44 insertions(+), 131 deletions(-) create mode 100644 packages/common/typings/global.d.ts create mode 100644 packages/common/typings/lodash.isequal/index.d.ts delete mode 100644 packages/common/webpack.config.js diff --git a/packages/common/package.json b/packages/common/package.json index 1f94f5416..5716f4dd6 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -44,6 +44,7 @@ "flatpickr": "^4.6.3", "jquery": "^3.4.1", "jquery-ui-dist": "^1.12.1", + "lodash.isequal": "^4.5.0", "moment-mini": "^2.24.0", "multiple-select-adapted": "^1.3.0", "slickgrid": "^2.4.19" @@ -54,7 +55,6 @@ "@types/jquery": "^3.3.33", "@types/moment": "^2.13.0", "@types/node": "^13.9.0", - "@types/webpack": "^4.41.7", "autoprefixer": "^9.7.4", "copyfiles": "^2.2.0", "cross-env": "^7.0.2", @@ -78,8 +78,7 @@ "ts-jest": "^25.2.1", "ts-loader": "^6.2.1", "typescript": "^3.8.3", - "url-loader": "^3.0.0", - "webpack": "^4.42.0" + "url-loader": "^3.0.0" }, "engines": { "node": ">=10.16.0", diff --git a/packages/common/typings/global.d.ts b/packages/common/typings/global.d.ts new file mode 100644 index 000000000..9e6c1dbd9 --- /dev/null +++ b/packages/common/typings/global.d.ts @@ -0,0 +1 @@ +import 'jest-extended'; diff --git a/packages/common/typings/lodash.isequal/index.d.ts b/packages/common/typings/lodash.isequal/index.d.ts new file mode 100644 index 000000000..2de9cef95 --- /dev/null +++ b/packages/common/typings/lodash.isequal/index.d.ts @@ -0,0 +1 @@ +declare module 'lodash.isequal'; diff --git a/packages/common/webpack.config.js b/packages/common/webpack.config.js deleted file mode 100644 index dbfeccc66..000000000 --- a/packages/common/webpack.config.js +++ /dev/null @@ -1,89 +0,0 @@ -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const { ProvidePlugin } = require('webpack'); -const ensureArray = (config) => config && (Array.isArray(config) ? config : [config]) || []; -const when = (condition, config, negativeConfig) => - condition ? ensureArray(config) : ensureArray(negativeConfig); -const path = require('path'); -// primary config: -const baseUrl = ''; -const outDir = path.resolve(__dirname, 'dist'); -const srcDir = path.resolve(__dirname, 'src'); -const srcLibDir = path.resolve(__dirname, 'src/slickgrid-universal'); -const nodeModulesDir = path.resolve(__dirname, 'node_modules'); -const cssRules = [ - { loader: 'css-loader' }, -]; -const platform = { - hmr: false, - open: false, - port: 8080, - host: 'localhost', - output: 'dist' -}; - -module.exports = ({ production } = {}, { extractCss, analyze, tests, hmr, port, host } = {}) => ({ - mode: production ? 'production' : 'development', - entry: { - app: [`${srcLibDir}/index.ts`], - }, - stats: { - warnings: false - }, - output: { - path: `${outDir}/bundle`, - publicPath: baseUrl, - filename: production ? 'slickgrid-grid-bundle.js' : 'slickgrid-grid-bundle.js', - sourceMapFilename: production ? 'slickgrid-grid-bundle.map' : 'slickgrid-grid-bundle.map', - libraryTarget: 'umd', - library: 'MyLib', - umdNamedDefine: true - }, - resolve: { - extensions: ['.ts', '.js'], - modules: [srcDir, 'node_modules'], - alias: { - moment$: 'moment/moment.js' - } - }, - module: { - rules: [ - // CSS required in JS/TS files should use the style-loader that auto-injects it into the website - // only when the issuer is a .js/.ts file, so the loaders are not applied inside html templates - { - test: /\.css$/i, - issuer: [{ not: [{ test: /\.html$/i }] }], - use: extractCss ? [{ - loader: MiniCssExtractPlugin.loader - }, - 'css-loader' - ] : ['style-loader', ...cssRules] - }, - { - test: /\.css$/i, - issuer: [{ test: /\.html$/i }], - // CSS required in templates cannot be extracted safely - // because Aurelia would try to require it again in runtime - use: cssRules - }, - { test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'], issuer: /\.[tj]s$/i }, - { test: /\.scss$/, use: ['css-loader', 'sass-loader'], issuer: /\.html?$/i }, - { test: /\.html$/i, loader: 'html-loader' }, - { test: /\.ts?$/, use: 'ts-loader', exclude: nodeModulesDir, }, - { test: /\.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } }, - { test: require.resolve('jquery'), loader: 'expose-loader?$!expose-loader?jQuery' }, - ], - }, - devtool: production ? 'nosources-source-map' : 'cheap-module-eval-source-map', - plugins: [ - new ProvidePlugin({ - '$': 'jquery', - 'jQuery': 'jquery', - 'window.jQuery': 'jquery', - 'window.$': 'jquery', - }), - ...when(extractCss, new MiniCssExtractPlugin({ // updated to match the naming conventions for the js files - filename: production ? 'slickgrid-grid-bundle.css' : 'slickgrid-grid-bundle.css', - chunkFilename: production ? 'slickgrid-grid-bundle.css' : 'slickgrid-grid-bundle.css' - })), - ] -}); diff --git a/packages/vanilla-bundle/package.json b/packages/vanilla-bundle/package.json index 1c46aa03e..f540eae71 100644 --- a/packages/vanilla-bundle/package.json +++ b/packages/vanilla-bundle/package.json @@ -10,11 +10,12 @@ "scripts": { "test": "echo testing slickgrid-universal slickgrid-vanilla-bundle code", "dev": "webpack --env.development", - "dev:watch": "webpack --env.development --watch", - "build": "webpack --env.development", + "dev:watch": "run-p build:watch", + "build": "cross-env tsc --build", + "build:watch": "cross-env tsc --incremental --watch", "bundle:commonjs": "tsc --project tsconfig.build.json --outDir dist/commonjs --module commonjs", "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2015 --target es2020", - "bundle": "npm-run-all webpack:prod bundle:commonjs bundle:es2020", + "bundle": "npm-run-all bundle:commonjs bundle:es2020 webpack:prod", "prebundle": "npm-run-all delete:dist delete:zip", "postbundle": "npm-run-all zip:dist", "delete:dist": "cross-env rimraf dist", diff --git a/packages/vanilla-bundle/tsconfig.json b/packages/vanilla-bundle/tsconfig.json index 39d01da12..ac4f199cc 100644 --- a/packages/vanilla-bundle/tsconfig.json +++ b/packages/vanilla-bundle/tsconfig.json @@ -1,40 +1,40 @@ { - "extends": "../tsconfig-build.json", - "compileOnSave": false, - "compilerOptions": { - "rootDir": "src", - "declarationDir": "dist", - "outDir": "dist/esnext", - "target": "es2017", - "module": "es2015", - "sourceMap": true, - "lib": [ - "esnext", - "dom" - ], - "types": [ - "moment", - "jquery", - "node" - ], - "typeRoots": [ - "node_modules/@types", - "src/typings" - ] - }, - "exclude": [ - "cypress", - "dist", - "node_modules", - "**/*.spec.ts" + "extends": "../tsconfig-build.json", + "compileOnSave": false, + "compilerOptions": { + "rootDir": "src", + "declarationDir": "dist/es2020", + "outDir": "dist/es2020", + "target": "es2017", + "module": "es2015", + "sourceMap": true, + "lib": [ + "es2020", + "dom" ], - "filesGlob": [ - "./src/**/*.ts", - "./test/**/*.ts", - "./custom_typings/**/*.d.ts" + "types": [ + "moment", + "jquery", + "node" ], - "include": [ - "src/**/*.ts", - "src/typings/**/*.ts" + "typeRoots": [ + "node_modules/@types", + "src/typings" ] -} \ No newline at end of file + }, + "exclude": [ + "cypress", + "dist", + "node_modules", + "**/*.spec.ts" + ], + "filesGlob": [ + "./src/**/*.ts", + "./test/**/*.ts", + "./custom_typings/**/*.d.ts" + ], + "include": [ + "src/**/*.ts", + "src/typings/**/*.ts" + ] +}